Link
shadcn-htmx/linkFreeComponent
A native <a href> with shadcn styling — default (underlined), muted, and hover-underline variants, plus an external treatment that opens a new tab, sets rel="noopener noreferrer", and announces "(opens in new tab)".
Live preview
live · rendered by the registry
Rendered by shadcn-htmx on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-htmx.productdevbook.com/r/link.jsonSource
1/** @jsxImportSource hono/jsx */2import type { PropsWithChildren } from "hono/jsx"3import { cn, type ClassValue } from "@/registry/lib/cn"45// Link — shadcn-htmx, htmx v4 + Tailwind v4.6//7// shadcn/ui has no standalone "link" primitive — it styles links through the8// Button `link` variant and the `typography` docs. We ship a dedicated,9// text-first anchor instead. Anatomy/intent cross-checked against the Button10// `link` variant: repos/shadcn-ui/apps/v4/registry/new-york-v4/ui/button.tsx.11//12// Accessibility contract — WAI-ARIA APG Link pattern:13// repos/aria-practices/content/patterns/link/link-pattern.html14// The APG itself says: "Authors are strongly encouraged to use a native host15// language link element, such as an HTML <a> element with an href attribute."16// So we render a real <a href>. That gives us, for free and without any JS:17// - the implicit `link` role (MDN: <a> has role=link when href is present —18// repos/mdn/files/en-us/web/html/reference/elements/a/index.md "Implicit19// ARIA role"),20// - Enter activates + moves focus to the target (the APG keyboard contract —21// link-pattern.html "Keyboard Interaction": Enter executes the link),22// - browser affordances the APG example flags as lost when you fake a link23// with role=link on a <span>: open-in-new-tab, copy-link, drag, Shift+F1024// context menu.25// The APG link *examples* (link/examples/link.html) only reach for26// role=link + tabindex=0 + onkeydown when the markup genuinely cannot be an27// <a> (a <span> or <img>). We expose that fallback via `as` + `role="link"`,28// but the default — and the path we document — is the native element.29//30// `external` sets target/rel and renders a visible "opens in new tab" icon +31// visually-hidden text, per MDN's "External links" guidance32// (a/index.md "External links and linking to non-HTML resources"). Modern33// browsers treat target="_blank" as rel="noopener" implicitly; we still emit34// rel="noopener noreferrer" so the protection is explicit and back-compatible.3536export type LinkVariant =37 | "default" // underlined, primary colour — reads as a link in prose38 | "muted" // muted-foreground, underlined — low-emphasis inline link39 | "hover" // no underline at rest, underline on hover/focus — nav/menu link4041const base =42 "inline-flex items-center gap-1 rounded-sm font-medium text-primary underline-offset-4 transition-colors outline-none " +43// … truncated
More from shadcn-htmx
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-htmx | Components | Free | no deps | |
| Active Searchactive-search | shadcn-htmx | Components | Free | no deps | |
| Alertalert | shadcn-htmx | Components | Free | no deps | |
| Alert Dialogalert-dialog | shadcn-htmx | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | shadcn-htmx | Components | Free | no deps | |
| Auto Gridauto-grid | shadcn-htmx | Components | Free | no deps | |
| Autocompleteautocomplete | shadcn-htmx | Components | Free | no deps | |
| Autosize Textareaautosize-textarea | shadcn-htmx | Components | Free | no deps |
