---
title: "Link · UI SDK — StyleX Blocks"
description: "Inline anchors with underline and plain hover treatments and a themed focus ring."
url: "https://stylexblocks.com/components/ui-sdk/link/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Link

Inline anchors with underline and plain hover treatments and a themed focus ring.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/link.md), [Base UI](https://stylexblocks.com/components/base-ui/link.md)
- Category: Typography
- Variants: underline, plain
- Used in blocks: [Analytics Dashboard](https://stylexblocks.com/block/ui-sdk/analytics-dashboard.md), [Basic Login](https://stylexblocks.com/block/ui-sdk/basic-login.md), [Checkout Form](https://stylexblocks.com/block/ui-sdk/checkout-form.md), [Contact Form](https://stylexblocks.com/block/ui-sdk/contact-form.md), [Documentation Catalog](https://stylexblocks.com/block/ui-sdk/documentation-catalog.md), [Documentation Technical](https://stylexblocks.com/block/ui-sdk/documentation-technical.md), [Two-Column Form](https://stylexblocks.com/block/ui-sdk/form-two-column.md), [Login Card](https://stylexblocks.com/block/ui-sdk/login-card.md), [Login Split](https://stylexblocks.com/block/ui-sdk/login-split.md), [Login SSO](https://stylexblocks.com/block/ui-sdk/login-sso.md), [Portfolio Dashboard](https://stylexblocks.com/block/ui-sdk/portfolio-dashboard.md), [Work Item Detail](https://stylexblocks.com/block/ui-sdk/work-item-detail.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/link/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add link
```

Equivalent: `npx shadcn add @stylexblocks/link`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/link.json

## Usage

```tsx
import { Link } from "#components/ui/ui-sdk/link.tsx";

export function Example() {
  return (
    <>
      {/* the variant prop resolves through the StyleX recipe and is
          exposed as a data-variant attribute */}
      <Link href="/docs" variant="underline">Read the docs</Link>

      {/* composition: the render prop replaces the underlying element,
          e.g. a router's link component */}
      <Link variant="plain" render={<RouterLink to="/pricing" />}>
        Pricing
      </Link>
    </>
  );
}
```

## Source

`components/ui/ui-sdk/link.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createComponent } from "#lib/ui-sdk/create-component.tsx";
import { defineRecipe } from "#lib/recipe-props.ts";
import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'

const linkStyles = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    outline: 'none',
    gap: spacing._1_5,
    cursor: 'pointer',
    borderRadius: semanticRadii.control,
    outlineWidth: {
      default: null,
      ':focus': '1px',
    },
    outlineOffset: {
      default: null,
      ':focus': '2px',
    },
    outlineStyle: {
      default: null,
      ':focus': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus': colorPalette.focusRing,
    },
  },
})

const linkVariants = stylex.create({
  underline: {
    color: colorPalette.fg,
    textDecoration: 'underline',
    textUnderlineOffset: '3px',
    textDecorationColor: 'currentColor/20',
  },
  plain: {
    color: colorPalette.fg,
    textDecoration: {
      default: null,
      ':hover': 'underline',
    },
    textUnderlineOffset: {
      default: null,
      ':hover': '3px',
    },
    textDecorationColor: {
      default: null,
      ':hover': 'currentColor/20',
    },
  },
})

export type LinkVariant = keyof typeof linkVariants

/**
 * Link — recipe and component colocated in one file. The variant prop
 * resolves mechanically from the axis map. Composition via `render`.
 */
const linkRecipe = defineRecipe({
  styles: linkStyles,
  axes: { variant: linkVariants },
  defaultVariants: { variant: "plain" },
});

export const Link = createComponent("a", linkRecipe, "Link");

export type LinkProps = React.ComponentProps<typeof Link>;
```
