What is Islands Architecture?
Islands architecture is a component-based architecture where interactive components (islands) are embedded within otherwise static HTML pages. Think of your page as an ocean of static HTML with scattered islands of interactivity.Key Concept: Only the interactive components are shipped to the client as JavaScript, while the rest of the page remains static HTML. This dramatically reduces the amount of JavaScript sent to the browser.
How It Works
By default, Astro renders all components to static HTML on the server with zero client-side JavaScript. When you need interactivity, you opt-in using client directives.Navigationrenders as static HTML (no JavaScript)Counterbecomes an interactive island that hydrates on the client
Client Directives
Client directives tell Astro when and how to hydrate your interactive components. These directives are added as attributes to your component tags.client:load
Hydrates the component immediately on page load.
- Usage
- Implementation
Use
client:load for high-priority UI that needs to be interactive immediately, like a navigation menu or chat widget.client:idle
Hydrates the component when the browser is idle (uses requestIdleCallback).
This is the recommended directive for most interactive components. It waits until the main thread is free before hydrating.
- Usage
- Implementation
Ideal for lower-priority UI that doesn’t need to be immediately interactive, like comment sections, social media embeds, or analytics widgets.
client:visible
Hydrates the component when it enters the viewport (uses IntersectionObserver).
- Usage
- Options
- Implementation
Perfect for components below the fold, like image carousels, infinite scroll loaders, or any content that might not be immediately visible.
client:media
Hydrates the component when a CSS media query matches.
- Usage
- Implementation
Useful for components that only make sense at certain screen sizes, like mobile-specific navigation or desktop-only features.
client:only
Skips server-side rendering and only renders the component on the client.
Practical Example
Here’s a complete page showing different hydration strategies:Benefits
Faster Performance
Less JavaScript means faster page loads and better Core Web Vitals scores.
Better SEO
Content is rendered as HTML on the server, making it immediately crawlable by search engines.
Progressive Enhancement
Pages work with JavaScript disabled, then enhance when it loads.
Framework Agnostic
Mix React, Vue, Svelte, and other frameworks on the same page.
Technical Implementation
Astro wraps hydrated components in custom<astro-island> elements. From the source code (src/runtime/server/hydration.ts), the system:
- Extracts client directives from component props
- Validates the directive is supported
- Generates hydration metadata
- Wraps the component in an
<astro-island>with hydration instructions
Best Practices
Add interactivity selectively
Only use framework components (React, Vue, etc.) where you need client-side interactivity.
Choose the right directive
client:loadfor critical UIclient:idlefor most interactive componentsclient:visiblefor below-the-fold contentclient:mediafor responsive componentsclient:onlyas a last resort
Learn More
Components
Learn about Astro’s component model
Routing
Understand Astro’s file-based routing