Link
Introduction
Section titled “Introduction”The Link component provides a robust solution for creating accessible links that seamlessly handle both internal navigation and external destinations. It automatically detects external links and applies appropriate attributes for security and accessibility, while offering optional button styling for enhanced visual impact.
When to use
Section titled “When to use”Use the Link component when you need to:
- Navigate between pages in your application
- Link to external websites or resources
- Create button-styled links for call-to-action elements
- Ensure consistent link accessibility across your site
- Automatically handle external link security and accessibility
- Add animated interactions to link buttons
- Maintain proper focus management and keyboard navigation
Quick example
Section titled “Quick example”Try hovering over the “Get Started” button to see the animation effect!
Button Types and Variants
Section titled “Button Types and Variants”All button types from the Button component are available here. Here’s a few examples of the available button types, variants, and sizes:
Button Types (Filled)
Section titled “Button Types (Filled)”Button Types (Outlined)
Section titled “Button Types (Outlined)”Button Sizes
Section titled “Button Sizes”Animations
Section titled “Animations”Available animations are the same as the Button component animations.
Learn how to implement the Link component in your project, from basic navigation to advanced button-styled links.
Basic links
Section titled “Basic links”---import { Link } from 'accessible-astro-components'---
<!-- Internal link --><Link href="/about">About Us</Link>
<!-- External link (automatically detected) --><Link href="https://astro.build">Visit Astro</Link>
<!-- Explicitly mark as external --><Link href="https://example.com" isExternal>External Site</Link>
Button-styled links
Section titled “Button-styled links”<Link href="/contact" isButton>Contact Us</Link><Link href="/signup" isButton type="primary">Sign Up</Link><Link href="/docs" isButton variant="outlined">Documentation</Link>
Different button types and sizes
Section titled “Different button types and sizes”<Link href="#" isButton type="info" size="sm">Small Info</Link><Link href="#" isButton type="success" size="md">Medium Success</Link><Link href="#" isButton type="warning" size="lg">Large Warning</Link><Link href="#" isButton type="error">Error Button</Link>
With icons and animations
Section titled “With icons and animations”---import { Link } from 'accessible-astro-components'import { Icon } from 'astro-icon/components'---
<Link href="/dashboard" isButton type="primary" animateOnHover animationType="boop"> <Icon name="ion:home" /> Dashboard</Link>
<Link href="/settings" isButton animateOnHover animationType="rotate" animationIntensity={8}> <Icon name="ion:settings" /> Settings</Link>
External links with custom icons
Section titled “External links with custom icons”<Link href="https://github.com/incluud"> GitHub Repository <Icon name="ion:logo-github" slot="icon" /></Link>
Accessible link practices
Section titled “Accessible link practices”<!-- Link with descriptive aria-label --><Link href="/download" isButton type="success" ariaLabel="Download the complete user guide PDF"> <Icon name="ion:download" /> Download</Link>
<!-- Link with title for additional context --><Link href="https://example.com" title="Opens in a new tab - Example website"> Visit Example</Link>
Configure the Link component using these available props to customize its behavior and appearance.
Prop | Type | Default | Description |
---|---|---|---|
href | string | Required | The URL to link to |
isExternal | boolean | false | Whether the link is external (auto-detected for http/https URLs) |
hideIcon | boolean | false | Whether to hide the external link icon |
isButton | boolean | false | Style the link as a button |
variant | 'filled' | 'outlined' | 'filled' | The variant of the link when styled as button |
type | 'default' | 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'error' | 'ghost' | 'default' | Type affecting color scheme when styled as button |
size | 'sm' | 'md' | 'lg' | 'md' | Button size when styled as button |
ariaLabel | string | '' | The aria-label attribute |
title | string | '' | The title attribute |
animateOnHover | boolean | false | Whether to animate icons on hover (only when isButton is true) |
animationType | 'rotate' | 'boop' | 'bouncing' | 'none' | 'boop' | Type of animation to apply on hover |
animationIntensity | number | 5 | Animation intensity (1-10) |
pulse | boolean | false | Whether to apply a pulsating animation |
class | string | '' | Additional CSS classes to apply |
Accessibility
Section titled “Accessibility”The Link component is built with accessibility as a core principle, ensuring inclusive navigation for all users:
- Semantic HTML: Uses proper anchor (
<a>
) elements for all links - External link indicators: Automatically adds visual icons and screen reader text for external links
- Security attributes: External links include
target="_blank"
andrel="noopener noreferrer"
- Keyboard navigation: Full keyboard support with proper focus management
- Screen reader support: Contextual information for assistive technologies
- High contrast: Color combinations meet WCAG contrast requirements
- Motion preferences: Respects
prefers-reduced-motion
for animations - Focus indicators: Clear focus states for keyboard navigation
Styling
Section titled “Styling”Customize the Link component’s appearance while preserving its accessibility features and functionality.
/* Option 1: Using :global() in your style block */<style> :global(.link) { color: var(--accent-color); text-decoration-thickness: 2px; text-underline-offset: 4px; }
:global(.link--external) { color: var(--external-link-color); }
:global(.link--external svg) { color: var(--accent-color); }
:global(.button) { border-radius: 8px; font-weight: 600; letter-spacing: 0.025em; }
:global(.button.type-primary) { background: linear-gradient(135deg, var(--primary-color), var(--primary-dark)); border-color: var(--primary-dark); }
:global(.button:focus-visible) { outline: 3px solid var(--focus-color); outline-offset: 2px; }</style>
/* Option 2: Using is:global on the style tag */<style is:global> .link { color: var(--accent-color); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.button { border-radius: 8px; font-weight: 600; letter-spacing: 0.025em; }</style>
<Link class="font-semibold tracking-wide underline-offset-4" href="/custom-styled"> Custom Styled Link</Link>
<Link class="rounded-lg shadow-lg transform transition-transform hover:scale-105" href="/enhanced-button" isButton type="primary"> Enhanced Button</Link>
Interactive examples
Section titled “Interactive examples”Explore the Link component in action with these practical examples showcasing different configurations and styling approaches.
Navigation links
Section titled “Navigation links”Call-to-action buttons
Section titled “Call-to-action buttons”Animated interactive buttons
Section titled “Animated interactive buttons”Hover over the buttons to see different animation effects!
Different sizes and variants
Section titled “Different sizes and variants”Accessible external links
Section titled “Accessible external links”These links provide proper context for screen readers while maintaining clean visual design.