Skip to Content
CodeUI

Link

@codeui/styles v0.3.0

An inline navigation link in plain HTML, with an optional hover underline.

Load @codeui/styles/link.css, or all.css. The Solid component is documented in Link.

Demo

link/basic.html
<a href="https://codeimage.dev" class="cui-link" data-cui="link" data-variant="default">Open CodeImage</a>

Markup

PartElementClassdata-cui
Rootacui-linklink

The root inherits its text color and line height from its parent.

AttributeValuesDefault
data-variantdefault, underlinedefault

Variants

link/variants.html
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true">  <a href="https://codeimage.dev" class="cui-link" data-cui="link" data-variant="default">Open CodeImage</a>  <a href="https://codeimage.dev" class="cui-link" data-cui="link" data-variant="underline">Open CodeImage with hover underline</a></div>

default has no underline. data-variant="underline" adds an underline on hover only. There are no color or size attributes. Put decorative icons in the children.

In running text

link/in-text.html
<p class="cui-text" data-cui="text" data-tone="muted" style="margin: 0; max-width: 420px">  Snippets export at 2x by default. Change the scale in  <a href="#export-settings" class="cui-link" data-cui="link" data-variant="underline">export settings</a>,  or  <a href="https://github.com/riccardoperra/codeimage" class="cui-link" data-cui="link" data-variant="underline" target="_blank" rel="noopener noreferrer">view the source (opens in a new tab)</a>.</p>

The link takes the color of the text around it. Use underline when a link sits inside a sentence, so the hover shows it is a link. Say in the link text when it opens a new tab.

States

Disabled

link/disabled.html
<a role="link" aria-disabled="true" class="cui-link" data-cui="link" data-variant="default" data-disabled>Export history unavailable</a>

The stylesheet has no disabled style. To disable a link, remove href, set role="link" and aria-disabled="true", and add data-disabled for your own selectors. Without href the anchor leaves the tab order.

What you supply

  • A visible focus style. The class sets outline: none and draws no focus ring, so add a :focus-visible rule in your app.
  • Link text that names the destination, and rel="noopener noreferrer" with target="_blank".
  • Routing, if a client router handles the click.

Helper

import "@codeui/styles/link.css";
import { applyStyleProps } from "@codeui/styles";
import { linkStyleProps } from "@codeui/styles/link";

const source = document.querySelector("a")!;
applyStyleProps(source, linkStyleProps({ variant: "underline" }));
// class="cui-link" data-cui="link" data-variant="underline"

On this page