Links serve as navigational elements that assist users to move within a page, to a different page on the same website, or to external websites and resources.
Configurator
LiveLink: inverted variants belong on dark grounds, switch the scheme to Dark to try them.
Primary Links are used for the most important links on a page or for inline links.
Secondary Links are intended for less important links on a page. Be careful when using them as they have a lower click affordance compared to primary links.
Sale Links are used for content that is used in the context of a sale, for example, 'Sale' categories in the navigation menu.
Underlined Links are only placed on light colored backgrounds. They come in regular and bold.
Inverted Links are only placed on dark backgrounds. They come in regular and bold.
You can also add an Icon to the left or right of the Link. Icons are optional and can be placed on either side of the Link. They visually communicate the Link's target and enhance user attention. Left-side Icons help reduce cognitive load by symbolizing the Link's action. Icons on the right are used as affordance for the interaction; for example, a leaving-page denotes an external target.
Link 100 and link 125 use icons in size 100, while link 75 and link 50 use icons in size 50.
<span style="background:rgba(229,0,107,.08);outline:1px dashed #e5006b"><oc-link-v2 size="125"><a href="#">Alles zu Lieferung und Versand</a></oc-link-v2></span>
Placement
Links can be placed in two ways: as stand-alone elements or inline within the surrounding text.
When inserting a link around continuous text, use the inline variant. This will underline the link, meeting WCAG Success Criterion 1.4.1 Use of Color. When using inline links, it is important to match the size of the link with the surrounding text. The technical size "inherit" may be used for that case.
A link directs the user away from their current journey for exploration or additional information. Links can be used to move within a page, to a different page on the same website or to external websites and resources.
Whereas a button keeps the user within their current journey or move them to the next or previous step in that journey. They often trigger actions that support completing a task, like submitting a form, confirming an action, changing content or loading new content without disrupting the flow.
Don'tMix different link styles in the same context.
Content guidelines
DoUse specific labels that clearly convey the link's function or destination.Don'tUse generic or vague labels, such as "Hier klicken", "Jetzt entdecken" or "Mehr erfahren".DoKeep link labels short concise.Don'tUse lengthy sentences with punctuation marks for the label.
Accessibility
Be aware, that link 50 and 75 have an undersized as per WCAG SC 2.5.8 Target Size. That means that they have to maintain enough spacing of 24px from the center of the target to adjacent links. For that reason they have to maintain 8px vertical spacing to each other and can not be used within other interactive elements like cards.
The Link component provides a clickable text element with attributes for setting the URL, base64 encoded URL for SEO purposes, ARIA label for accessibility, and emitting a click event when interacted with.
It can also behave as a button and trigger an action instead of navigating to a new page.
The native a tag is moved to the default slot for SEO purposes.
Can be one of: primary, secondary, over-color, over-color-bold, inverted, inverted-bold. Deprecated: underlined, underlined-bold, on-color, on-color-bold.
size
"50" | "100" | "75" | "125" | "inherit"
"100"
no
Sets the font of the link component. Can be one of: 50, 75, 100, 125 or inherit.
If you want to use the font size of the parent element, set the size attribute to inherit.
Sets the base64 encoded link target of the link component. Use this attribute to prevent search engines from indexing the link target.
target
"_blank" | "_self" | "_parent" | "_top"
undefined
no
Sets the target attribute of the link.
Note Only applies when href or base64Href is set.
rel
string
undefined
no
Sets the rel attribute of the link.
Note Only applies when href or base64Href is set.
as-button
boolean
false
no
Determines if the link behaves as a button. Set to true to make the link behave as a button and trigger an action instead of navigating to a new page.
oc-aria-label
string
undefined
no
Sets the ARIA label of the link.
Note This attribute is not available when using an a tag in the default slot. Instead, use the aria-label attribute on the a tag in the default slot.
Slots
Slot
Required
Description
default
yes
Sets the content of the link component.
Events
Event
Detail type
Description
click
PointerEvent
Clicking the link or pressing the Enter or Space key while the link is focused triggers the click event. Use this event in case the as-button attribute is set to true.
oc-property-change
OcLinkV2Events["oc-property-change"]
Whenever a property value changes, this event triggers. Use this event to track all property changes within the component.
Fired when the component is mounted to the DOM. The event is fired when the onMount hook of the component is called by the runtime.
oc-unmount
{ component: string; }
Fired when the component is unmounted from the DOM. The event is fired when the function returned by the onMount hook of the component is called by the runtime.
Methods
focus: () => void
Calls the native focus() method on the underlying element.
This is a convenience method that internally uses invoke("focus").
Returns: void
Example:
const link = document.querySelector("oc-link-v2");
link.focus();
click: () => void
Calls the native click() method on the underlying element.
This is a convenience method that internally uses invoke("click").
Returns: void
Example:
const link = document.querySelector("oc-link-v2");
link.click();
goto: () => void
This is a shorthand function that combines three operations:
Unmasks the link href (if it's base64-encoded)
Focuses the link element
Clicks the link element
This method simulates a complete user interaction with the link.
It is especially useful for testing masked links.
Returns: void
Example:
const link = document.querySelector("oc-link-v2[base64-href]");
link.goto();
unmask: () => void
Calls the underlying unmasking function to decode and apply the base64-encoded href.
This is used when the link is rendered with the base64-href attribute for SEO purposes.
Normally, unmasking happens automatically on user interaction, but this method allows you to trigger it programmatically for integration testing or other scenarios.
Returns: void
Example:
const linkElement = document.querySelector("oc-link-v2[base64-href]");
// Unmask the link programmatically
linkElement.unmask();
// Now the href is accessible
console.log(linkElement.href);
dispatch: <E extends Event>(event: E) => void
Calls dispatchEvent on the underlying element to dispatch the given event.
This is useful for testing purposes, to simulate user interactions or to trigger custom events on the underlying element.
Parameters:
event: E The event to dispatch on the underlying element
Returns: void
Example:
const linkElement = document.querySelector("oc-link-v2");
// Dispatch a custom event
const customEvent = new CustomEvent("custom-action", {
detail: { action: "track-click" },
});
linkElement.dispatch(customEvent);
// Dispatch a native event
const mouseEvent = new MouseEvent("mouseenter");
linkElement.dispatch(mouseEvent);
invoke: <R>(methodIdentifier: string, ...args: unknown[]) => R
Genric helper method used to invoke (call) functions on the underlying element which currently
acts as link in the link component. This is useful in cases where there is no light dom element
of the state of the link is not deterministic.
The method will invoke the function on either a light dom link. element if it exists,
or on the underlying element inside shadow dom in cases there is no light dom anchor.
The result of the method depends on the implementation of the underlying element
and must be assured by the consumer of the component.
If there is no suitable element or method to invoke, it will return undefined.
This function will only produce errors if the underlying method throws an error.
The function will not throw if the invocation is not possible.
Parameters:
methodIdentifier: string The name of the method to invoke on the underlying element
args: unknown[] The arguments to pass to the method
Returns: R The result of the method invocation, or undefined if the element or method does not exist
CSS custom properties
Custom property
Default
Description
--icon-gap
"var(--oc-semantic-spacing-relative-25)"
Sets the gap between the icons and the text content of the link. This applies only when at least one of the icons is set.
Examples
Listed below are the most common variations of the link component as well as specific component variations for different use cases.
Inline
The inline attribute allows the link to be rendered inline with a decorative underline.
Du kannst deine Bestellung innerhalb von 30 Tagen kostenlos zurücksenden. Wo dein Paket gerade ist, siehst du unter Meine Bestellungen. Fragen beantwortet dir gern unser Kundenservice.
Alle Infos zur Rücksendung
HTML
<div style="display: flex; gap: 16px;">
<div style="max-width: 456px; border: 1px solid #ccc; padding: 16px;">
<span class="oc-copy-100">Du kannst deine Bestellung innerhalb von 30 Tagen kostenlos <oc-link-v2 size="inherit" inline="true">zurücksenden</oc-link-v2>. Wo dein Paket gerade ist, siehst du unter <oc-link-v2 size="inherit" inline="true">Meine Bestellungen</oc-link-v2>. Fragen beantwortet dir gern unser <oc-link-v2 size="inherit" inline="true">Kundenservice</oc-link-v2>.</span>
<br />
<oc-link-v2 size="inherit"
>Alle Infos zur Rücksendung</oc-link-v2
>
With button behavior
Variation of the default configuration using the as-button attribute to trigger an action when clicked instead of navigating to a new page.
Link
HTML
<oc-link-v2 as-button>Link</oc-link-v2>
With masked link behavior
The link component as a masked link. Search engines will not detect the href.
Link
HTML
<oc-link-v2 base64-href="Iw==">Link</oc-link-v2>
Link size inherit
Variation link size inherit using the size attribute with the value inherit. This will use the font size of the parent element.
<h1 class="oc-headline-300">
<oc-link-v2 size="inherit" style="display: block"><a href='#'>Link within a headline</a></oc-link-v2>
</h1>
Demo: Inline links
Demo with inline links.
Du kannst deine Bestellung innerhalb von 30 Tagen kostenlos zurücksenden. Wo dein Paket gerade ist, siehst du unter Meine Bestellungen. Fragen beantwortet dir gern unser Kundenservice.
Du kannst deine Bestellung innerhalb von 30 Tagen kostenlos zurücksenden. Wo dein Paket gerade ist, siehst du unter Meine Bestellungen. Fragen beantwortet dir gern unser Kundenservice.
HTML
<div style="display: flex; gap: 16px;">
<div style="max-width: 456px; border: 1px solid #ccc; padding: 16px;">
<p class="oc-copy-100">Du kannst deine Bestellung innerhalb von 30 Tagen kostenlos <oc-link-v2 size="inherit">zurücksenden</oc-link-v2>. Wo dein Paket gerade ist, siehst du unter <oc-link-v2 size="inherit">Meine Bestellungen</oc-link-v2>. Fragen beantwortet dir gern unser <oc-link-v2 size="inherit">Kundenservice</oc-link-v2>.</p>
<div
style="max-width: 456px; border: 1px solid #ccc; padding: 16px; background-color: var(--oc-semantic-color-inverted-background) !important;"
>
<p class="oc-copy-100" style="color: var(--oc-semantic-color-text-inverted) !important;">Du kannst deine Bestellung innerhalb von 30 Tagen kostenlos <oc-link-v2 variant="inverted" size="inherit">zurücksenden</oc-link-v2>. Wo dein Paket gerade ist, siehst du unter <oc-link-v2 variant="inverted" size="inherit">Meine Bestellungen</oc-link-v2>. Fragen beantwortet dir gern unser <oc-link-v2 variant="inverted" size="inherit">Kundenservice</oc-link-v2>.</p>
Older versions
Migration to v2
Migration from Link v1 to v2
The oc-link component has been updated from oc-link-v1 to oc-link-v2.
This migration guide provides a step-by-step guide to update your project to the latest version.
The link is now a proper web component instead of a CSS-only class, providing:
Encapsulated styling
Consistent behavior across the application
Better integration with other Otto Components
SEO-friendly links
The <a> tag is placed inside the component slot, preserving native link behavior for search engine crawlers.
API changes
Changed structure
v1 (CSS class)
v2 (Web Component)
Notes
<a class="oc-link-v1">
<oc-link-v2><a>...</a></oc-link-v2>
Link moved to slot
<button class="oc-link-v1">
<oc-link-v2 as-button>
Component handles button styling
oc-link-v1--primary
variant="primary" (default)
Default variant
oc-link-v1--secondary
variant="secondary"
No change
oc-link-v1--underlined
variant="underlined"
No change
oc-link-v1--underlined-bold
variant="underlined-bold"
No change
oc-link-v1--size-50
size="50"
No change
oc-link-v1--size-75
size="75"
No change
oc-link-v1--size-100
size="100"
No change
oc-link-v1--size-125
size="125"
No change
How to migrate
Instead of using a div with the oc-link-v1 class, use the oc-link-v2 component tag to create a link.
The oc-link-v2 component can be used as a link or button by adding the href or as-button attribute respectively.
Here's a table mapping deprecated CSS classes to their corresponding replacement attributes in the new version:
CSS-Class (V1)
Attribute (V2)
Notes
oc-link-v1--primary
variant="primary" (default)
Default variant
oc-link-v1--secondary
variant="secondary"
No change
oc-link-v1--underlined
variant="underlined"
No change
oc-link-v1--underlined-bold
variant="underlined-bold"
No change
oc-link-v1--size-50
size="50"
No change
oc-link-v1--size-75
size="75"
No change
oc-link-v1--size-100
size="100"
No change
oc-link-v1--size-125
size="125"
No change
Migrate a basic link
To migrate a basic link, replace the anchor tag <a> including the oc-link-v1 class with the oc-link-v2 component tag and keep the href attribute.
<!-- To: -->
<oc-link-v2>
<a href="#">My Link</a>
</oc-link-v2>
Migrate a link with a variant
To migrate a link with a variant, replace the anchor tag <a> including the oc-link-v1 class with the oc-link-v2 component tag and add the variant attribute with the desired value.
<!-- To: -->
<oc-link-v2 variant="secondary">
<a href="#">My Link</a>
</oc-link-v2>
Migrate a link with a size
To migrate a link with a size, replace the anchor tag <a> including the oc-link-v1 class with the oc-link-v2 component tag and add the size attribute with the desired value.
<!-- To: -->
<oc-link-v2 size="50">
<a href="#">My Link</a>
</oc-link-v2>
Migrate a link as a button
To migrate a link as a button, replace the button tag including the oc-link-v1 class with the oc-link-v2 component tag and add the as-button attribute.