usmds docs

Link

Links allow users to navigate to different pages or external resources.

Installation

npx usmds add link

Usage

import { Link } from '@components/Link';
 
<Link href="#" label="Link text" />

Props

Extends Pressable props.

PropTypeDefaultDescription
hrefstring-The URL that the link points to.
labelstring-The text content of the link.
variant'default' | 'visited' | 'dark-background''default'The visual style variant of the link.
externalbooleanfalseWhen true, displays an external link icon.
visitedbooleanfalseWhen true, applies visited link styling.
focusbooleanfalseWhen true, applies focus ring styling.
classNamestring-Additional Tailwind classes to apply.

Examples

<Link href="#" label="Link" />
<Link 
  href="https://example.com" 
  label="External link" 
  external 
/>
<Link 
  href="#" 
  label="Visited link" 
  visited 
/>

Dark Background

<View className="bg-base-darker p-4">
  <Link 
    href="#" 
    label="Link on dark background" 
    variant="dark-background" 
  />
</View>

Focus State

<Link 
  href="#" 
  label="Focused link" 
  focus 
/>

Styling

The Link component uses Tailwind CSS classes for styling through class-variance-authority (cva). Default styling includes:

  • Font: Source Sans Pro
  • Base text size with 162% line height
  • Underlined text
  • Primary color (default variant)
  • Focus ring when focused
  • External link icon spacing (when external)
  • Visited state color
  • Dark background variant for contrast

States

Links have several visual states:

  • Default: Primary color
  • Visited: Violet color
  • Focus: Blue focus ring
  • Dark background: Light primary color
  • External: Includes external link icon

Accessibility

The Link component:

  • Uses semantic link structure
  • Supports keyboard navigation
  • Maintains WCAG color contrast requirements
  • Provides visual feedback for interaction states
  • Includes external link indicators where appropriate
  • Uses proper text spacing for readability

On this page