DwsLink
DwsLink renders a real link element with an href: internal pages are opened through the library's navigation (unsaved-data prompt, no full reload), while Ctrl / Cmd / Shift + click and the middle button still open a new tab or window. Without an Href but with OnClick it becomes a keyboard-operable role='button'. StartIcon and EndIcon are decorative DwsIcons in the link's colour and size.
API ReferenceBasic link
A plain internal link with Href.
Show Code
Link.razor
<DwsLink Name="LinkDemo_Link01" Href="link">A plain internal link</DwsLink>Colour
Color sets the link colour from the theme.
Show Code
Link.razor
<DwsLink Name="LinkDemo_Link03" Href="link" Color="@DwsColor.Success">A coloured link</DwsLink>Icons
StartIcon and EndIcon add a decorative icon before or after the text.
Show Code
Link.razor
<DwsLink Name="LinkDemo_Link05" Href="link" StartIcon="@Icons.Regular.HandPointLeft">Icon at the start</DwsLink><br />
<DwsLink Name="LinkDemo_Link06" Href="link" EndIcon="@Icons.Regular.HandPointRight">Icon at the end</DwsLink>Disabled
A disabled link renders no href, so it cannot be followed, focused or opened in a new tab.
Show Code
Link.razor
<DwsLink Name="LinkDemo_Link07" Href="link" Disabled="true">Disabled link</DwsLink>Underline mode
When the link is underlined: always, on hover and keyboard focus only (the default), or never. A link that is never underlined turns slightly transparent on hover and focus instead (CSS variable --dws-link-hover-opacity, default 0.75).
Show Code
Link.razor
<DwsLink Name="LinkDemo_UnderlineAlways" Href="link" UnderlineMode="@DwsLinkUnderlineMode.Always">Always underlined</DwsLink><br />
<DwsLink Name="LinkDemo_UnderlineOnHover" Href="link" UnderlineMode="@DwsLinkUnderlineMode.OnHover">Underlined on hover (default)</DwsLink><br />
<DwsLink Name="LinkDemo_UnderlineNone" Href="link" UnderlineMode="@DwsLinkUnderlineMode.None">Never underlined</DwsLink>Typography
TypographyMode applies a typography preset to the link text.
Show Code
Link.razor
<DwsLink Name="LinkDemo_TypographyCaption" Href="link" TypographyMode="@DwsTypographyType.Caption">Caption link</DwsLink><br />
<DwsLink Name="LinkDemo_TypographySubtitle" Href="link" TypographyMode="@DwsTypographyType.Subtitle">Subtitle link</DwsLink><br />
<DwsLink Name="LinkDemo_TypographyHeading4" Href="link" TypographyMode="@DwsTypographyType.Heading4">Heading4 link</DwsLink>Custom icon RenderFragment
StartIconTemplate / EndIconTemplate replace the icon class with any markup.
Show Code
Link.razor
<DwsLink Name="LinkDemo_CustomStartIcon" Href="link">
<StartIconTemplate><DwsChip Name="LinkDemo_CustomStartIcon_Chip" Text="New" Color="DwsColor.Success" Size="DwsSize.Small" /></StartIconTemplate>
<ChildContent>Link with its own badge</ChildContent>
</DwsLink>Target mode
Opens the link in the current tab or in a new one (rel='noopener noreferrer' is added). External and mailto: links are always left to the browser. Ctrl / Cmd + click on the internal link opens it in a new tab.
Show Code
Link.razor
<DwsLink Name="LinkDemo_TargetCurrent" Href="about" TargetMode="@DwsLinkTarget.Current">Current tab (default)</DwsLink><br />
<DwsLink Name="LinkDemo_TargetBlank" Href="https://example.com" TargetMode="@DwsLinkTarget.Blank" EndIcon="@Icons.BS.BoxArrowUpRight">New tab</DwsLink><br />
<DwsLink Name="LinkDemo_TargetMail" Href="mailto:someone@example.com" StartIcon="@Icons.BS.Envelope">mailto: link</DwsLink>Long text, wrapping and inline use
A link inside running text wraps like the text around it; an unbroken URL breaks instead of pushing the page sideways on a phone.
Before you continue, please read the terms of service, the privacy policy and the separate agreement on the processing of personal data - they changed last month.
Unbroken URL: https://example.com/a/very/long/path/that/keeps/going/and/going/without/any/spaces/index.html?query=and-even-more-parameters
German: Datenschutzgrundverordnungskonformitätsbestätigung herunterladen
Show Code
Link.razor
<DwsTypography Name="LinkDemo_InlineLong_Text" Typography="DwsTypographyType.Paragraph" Class="mb-2" Style="max-width: 32rem">
Before you continue, please read the
<DwsLink Name="LinkDemo_InlineLong" Href="link" EndIcon="@Icons.BS.BoxArrowUpRight">terms of service, the privacy policy and the separate agreement on the processing of personal data</DwsLink>
- they changed last month.
</DwsTypography>
<DwsTypography Name="LinkDemo_LongUrl_Text" Typography="DwsTypographyType.Paragraph" Class="mb-2" Style="max-width: 32rem">
Unbroken URL:
<DwsLink Name="LinkDemo_LongUrl" Href="https://example.com/a/very/long/path/that/keeps/going/and/going/without/any/spaces/index.html?query=and-even-more-parameters">https://example.com/a/very/long/path/that/keeps/going/and/going/without/any/spaces/index.html?query=and-even-more-parameters</DwsLink>
</DwsTypography>
<DwsTypography Name="LinkDemo_German_Text" Typography="DwsTypographyType.Paragraph" Class="mb-0">
German: <DwsLink Name="LinkDemo_German" Href="link">Datenschutzgrundverordnungskonformitätsbestätigung herunterladen</DwsLink>
</DwsTypography>Tooltip
Tooltip is shown by DwsTooltip, not by the browser's title attribute: it opens on hover, on keyboard focus (Tab onto the link) and on a long press on a touch screen, and Escape closes it. It is the link's description (aria-describedby), the name stays the link text. TooltipPosition picks the preferred side. A disabled link can still explain why.
Inside a sentence the link stays inline: a link with a tooltip Opens this page again, and the text goes on after it.
Show Code
Link.razor
<DwsTypography Name="LinkDemo_Tooltip_Text" Typography="DwsTypographyType.Paragraph">
Inside a sentence the link stays inline:
<DwsLink Name="LinkDemo_Tooltip_Inline" Href="link" Tooltip="Opens this page again">a link with a tooltip</DwsLink>,
and the text goes on after it.
</DwsTypography>
<div class="d-flex flex-wrap gap-4 align-items-center">
@foreach (DwsTooltipPosition position in Enum.GetValues<DwsTooltipPosition>())
{
<DwsLink Name="@($"LinkDemo_Tooltip_{position}")" Href="link" Tooltip="@($"Tooltip on the {position.ToString().ToLowerInvariant()}")" TooltipPosition="@position">@position</DwsLink>
}
<DwsLink Name="LinkDemo_Tooltip_Disabled" Href="link" Disabled="true" Tooltip="Not available in the demo">Disabled, with a reason</DwsLink>
</div>Icon-only link
A link without text - an icon only - takes its name from AriaLabel; the tooltip describes it.
Show Code
Link.razor
@* No text: AriaLabel names the link, the tooltip describes it. *@
<DwsLink Name="LinkDemo_Tooltip_IconOnly" Href="link" AriaLabel="Settings" Tooltip="Open the settings" StartIcon="@Icons.BS.Gear"></DwsLink>Download
Download renders the download attribute: the browser saves the target (same-origin, blob: and data: URLs only) - an empty string keeps the file name of the URL.
Show Code
Link.razor
<DwsLink Name="LinkDemo_Download_Named" Href="favicon.ico" Download="dws-demo-icon.ico" StartIcon="@Icons.BS.Download">Download the favicon as dws-demo-icon.ico</DwsLink><br />
<DwsLink Name="LinkDemo_Download_Plain" Href="favicon.ico" Download="">Download with the file name of the URL</DwsLink>rel attribute
Rel replaces the rel attribute; on a new-tab link 'noopener' is kept unless the value itself says noopener, noreferrer or opener.
Show Code
Link.razor
<DwsLink Name="LinkDemo_Rel_Custom" Href="https://example.com" TargetMode="@DwsLinkTarget.Blank" Rel="nofollow">New tab, Rel="nofollow" (rendered: nofollow noopener)</DwsLink><br />
<DwsLink Name="LinkDemo_Rel_Same" Href="https://example.com/licence" Rel="license">Same tab, Rel="license"</DwsLink>External-link mark
ShowExternalIndicator adds a small mark after links that leave the application or open a new tab, with a text for screen readers.
Internal page in a new tab, with the mark(opens in a new tab)
Internal link: no mark although ShowExternalIndicator is set
Show Code
Link.razor
<DwsLink Name="LinkDemo_External_Same" Href="https://example.com" ShowExternalIndicator="true">External link with the mark</DwsLink><br />
<DwsLink Name="LinkDemo_External_Blank" Href="about" TargetMode="@DwsLinkTarget.Blank" ShowExternalIndicator="true">Internal page in a new tab, with the mark</DwsLink><br />
<DwsLink Name="LinkDemo_External_Internal" Href="about" ShowExternalIndicator="true">Internal link: no mark although ShowExternalIndicator is set</DwsLink>Interface-Description
| Name | Typ | Default | Description |
|---|---|---|---|
| Color | DwsColor | DwsColor.Primary | The link colour. |
| Href | string | string.Empty | The URL the link leads to. Empty or "#" renders no href: with OnClick the link is then a role="button". |
| TargetMode | DwsLinkTarget | DwsLinkTarget.Current | Opens the link in the current tab or in a new one ('_blank', with rel="noopener noreferrer"). |
| UnderlineMode | DwsLinkUnderlineMode | DwsLinkUnderlineMode.OnHover | When the link is underlined: always, on hover / focus only, or never. With None the link turns slightly transparent on hover / focus instead (CSS variable --dws-link-hover-opacity, default 0.75); a disabled link stays unchanged. |
| TypographyMode | DwsTypographyType? | null | Optional typography preset applied to the link text. |
| StartIcon | string | string.Empty | An optional icon class shown at the start of the link, as a decorative DwsIcon that keeps the link's colour and font size. |
| EndIcon | string | string.Empty | An optional icon class shown at the end of the link, as a decorative DwsIcon that keeps the link's colour and font size. |
| StartIconTemplate | RenderFragment? | null | Own markup shown instead of StartIcon. |
| EndIconTemplate | RenderFragment? | null | Own markup shown instead of EndIcon. |
| Tooltip | string | string.Empty | Text shown in a DwsTooltip on hover, on keyboard focus and on a long press (touch); Escape closes it. It is the link's description (aria-describedby), not its name. Only a link without any content takes it as its name. |
| TooltipPosition | DwsTooltipPosition | DwsTooltipPosition.Top | The side of the link the tooltip prefers; it moves to another side when it does not fit there. |
| AriaLabel | string? | null | Accessible name (aria-label) for a link whose content has no text, e.g. an icon only. A link with text is named by that text. |
| ChildContent | RenderFragment | default! | The link content. |
| OnClickPropagation | bool | true | Whether the click event bubbles up to the parent elements. |
| ShowVisited | bool | false | Gives a link the browser has already visited its own colour (:visited): the link colour shifted towards violet, or --dws-link-visited-color. |
| HrefFallback | bool | true | Blazor Server: when .NET cannot answer a click on an internal link (connection lost), the browser follows the href itself (full page load) - at once while the reconnect display is shown, otherwise after HrefFallbackDelay. OnClick, the unsaved-data prompt and the navigation events do not run for such a click. No effect in WebAssembly. |
| HrefFallbackDelay | int | 3000 | Milliseconds a click on an internal link may stay unanswered by .NET before the browser follows the href. 0: only a click made while the reconnect display is shown falls back. |
| Download | string? | null | Renders the download attribute: the browser saves the target instead of opening it. Empty string: the file name of the URL; any other value: the suggested file name. Honoured by browsers for same-origin, blob: and data: URLs. Such a link is left to the browser (no client-side navigation). |
| Rel | string? | null | The rel attribute. Null: 'noopener noreferrer' for a new-tab link, none otherwise. Empty string: no rel. On a new-tab link 'noopener' is added unless the value names noopener, noreferrer or opener. |
| ShowExternalIndicator | bool | false | Shows a small mark after the content of a link to another origin or one that opens a new tab, with a screen-reader text ('external link' / 'opens in a new tab'). Never shown for internal, mailto: or tel: links. |
| StartIconStyle | string | string.Empty | Inline style for the start icon. |
| EndIconStyle | string | string.Empty | Inline style for the end icon. |
| Name | Typ | Description |
|---|---|---|
| OnClick | EventCallback<MouseEventArgs> | Raised when the link is clicked (or, as a role="button" link, activated with Enter / Space). Not raised for Ctrl / Cmd / Shift + click on an internal link, which the browser opens in a new tab or window. |
| OnKeyUp | EventCallback<KeyboardEventArgs> | Raised when a key is released while the link has focus. Wired only when bound: an unbound key handler cost a server round trip per key press on Blazor Server. |
| OnKeyDown | EventCallback<KeyboardEventArgs> | Raised when a key is pressed while the link has focus. Wired only when bound, or for a role="button" link (no href, OnClick), which needs Enter / Space. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Element | ElementReference | The associated web component. May be null if accessed before the component is rendered. | |
| ComponentGuid | Guid | Unique identifier for the component. | |
| TypeString | string | The name of the component type, obtained from reflection. | |
| Authorized_RegisterEnabled | bool | false | Indicates whether this component is enabled through a permission registry. |
| Authorized_RegisterSelected | bool | false | Indicates whether this component is selected in permission selection mode. |
| GetInitializedState | bool | false | Returns whether the component is initialized. |
| GetRenderModeState | DwsRenderMode | Returns the current render mode. | |
| GetComponentState | DwsComponentStateType | Returns the current component state. | |
| GetIsInteractiveState | bool | false | Returns whether the component is interactive. |
| GetIsPrerenderingState | bool | false | Returns whether the component is prerendering. |
| GetComponentLoadingState | bool | false | Returns whether the component is loading. |
| IsFormBusy | bool | false | Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState). |
| Name | Typ | Parameters | Description |
|---|---|---|---|
| DebugInfo | void | Logs debug information about the component. | |
| UpdateState | void | Updates the component's state and triggers StateHasChanged. | |
| UpdateStateAsync | Task | Asynchronously updates the component's state and triggers StateHasChanged. | |
| Dispose | void | Disposes the component and releases resources. | |
| FocusAsync | ValueTask | bool containedInScrollableList | Sets focus to the component's element. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Name | string | Required unique identifier for the component within its container. | |
| Visible | bool | true | Determines if the component is visible in the UI. |
| Disabled | bool | false | Disables the form control, ensuring it doesn't participate in form submission. |
| ComponentNameSpace | string | The namespace for permission-based access control. | |
| PermissionKey | string? | null | A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins. |
| Class | string | Optional CSS class names. | |
| Style | string | Optional in-line styles. | |
| Tag | object | An optional user-defined object to store any additional data with the component. | |
| BackReference | DwsReference | A reference to the enclosing component. | |
| ID | string | The id of the <a> element. An id passed through AdditionalAttributes is used when ID is empty. | |
| AdditionalAttributes | Dictionary<string, object> | Further attributes of the <a> element (aria-describedby, data-*, hreflang, ...). Its class and style are merged with the link's own; aria-label, role, tabindex, aria-disabled and data-dws-prevent-keys are kept where the link sets none of its own. | |
| IgnorePermissionChecks | bool | false | Bypasses all permission checks for this component. |
| IgnorePermissionSelection | bool | false | Ignore permission selection mode for this component. |
| IgnoreFormBusy | bool | false | Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it. |
| Name | Typ | Description |
|---|---|---|
| OnInitializedCallbackStarted | EventCallback | Callback when OnInitialized starts. |
| OnInitializedCallback | EventCallback | Callback during OnInitialized. |
| OnInitializedCallbackCompleted | EventCallback | Callback when OnInitialized completes. |
| OnInitializedAsyncCallbackStarted | EventCallback | Callback when OnInitializedAsync starts. |
| OnInitializedAsyncCallback | EventCallback | Callback during OnInitializedAsync. |
| OnInitializedAsyncCallbackCompleted | EventCallback | Callback when OnInitializedAsync completes. |
| OnIsComponentLoadingChanged | EventCallback<bool> | Callback when IsComponentLoading changes. |
| OnCurrentRenderModeChanged | EventCallback<DwsRenderMode> | Callback when CurrentRenderMode changes. |
| OnComponentStateChanged | EventCallback<DwsComponentStateType> | Callback when ComponentState changes. |
