Islands & Client Interactivity
From static HTML to just enough interactivity
Section titled “From static HTML to just enough interactivity”The Foundations module made the case: Astro ships zero JavaScript by default. That’s great for content, but real sites still need a search box, a cart, a theme toggle, a like button. This module is about adding exactly that much interactivity — and no more.
The unit of interactivity in Astro is the island. An island is a framework component (React, Vue, Svelte, Solid, Preact) that you deliberately hydrate on the client with a client directive. Everything around it stays static HTML. You don’t opt the page into being an app; you opt one component into being interactive.
flowchart TB page["Page: static HTML, no JS"] page --> header["header — static"] page --> search["SearchBox — island (client:load)"] page --> article["article — static"] page --> cart["Cart — island (client:visible)"] page --> footer["footer — static"]
What this module covers
Section titled “What this module covers”| Lesson | What you’ll learn |
|---|---|
| Client directives | The five client:* directives and when each hydrates |
| Framework integrations | Using React/Vue/Svelte/Solid/Preact components as islands |
| Sharing state | Islands are isolated — how to share data across them with nanostores and slots |
| Server islands | server:defer — defer a slow or personalized component without slowing the page |
The mental model to carry through
Section titled “The mental model to carry through”Two questions decide everything in this module:
- Does this component need to be interactive at all? If not, it’s a plain
.astrocomponent and ships no JS. Most of the page. - If yes, when does it need to become interactive? Immediately? When it scrolls into view? At a certain screen size? That “when” is exactly what a client directive expresses — and it’s the difference between a fast page and a slow one.
Keep asking those two questions and islands stop being a bag of directives and become a budget: every island is JavaScript you chose to ship, on purpose.