Use Astro client:only when a framework component can’t be rendered on the server at all, typically because it reads window, localStorage or another browser API during render, or depends on a library that breaks in Node.js. Astro then skips the server HTML for that component and renders it only in the browser. You must name the framework, as in client:only="react", and you should give it a fallback, because nothing shows until the JavaScript runs.
Key Takeaways
client:onlyskips server rendering; every otherclient:*directive renders HTML first, then hydrates.- The framework hint (
"react","svelte","vue","preact","solid-js") is required.- Use a
slot="fallback"placeholder of the right size to avoid layout shift.- Content inside a
client:onlycomponent isn’t in the HTML, so crawlers and no-JS visitors don’t see it.
The syntax
---
// src/pages/dashboard.astro
import Chart from '../components/Chart.tsx';
---
<Chart client:only="react" data={points}>
<div slot="fallback" class="chart-skeleton" aria-hidden="true"></div>
</Chart>
<style>
.chart-skeleton { height: 320px; border-radius: 0.5rem; background: #f3f4f6; }
</style>
The fallback renders on the server and is replaced when the component mounts. Matching its height to the real component keeps the page from jumping.
Leaving out the framework name fails the build, because Astro can’t infer which renderer to load for a component it never renders on the server. Our tip on the missing client:only hint error shows the exact message and fix.
When client:only is the right call
- The component reads browser APIs during render, such as
window.innerWidth,localStorageormatchMedia, and you can’t move that code into an effect. - A third-party library crashes on the server, for example map, chart or editor libraries that touch
documentat import time. - The output depends on the visitor, such as a dashboard that reads a token from
localStorage, so server HTML would be wrong anyway. - It’s behind a login or below everything else, where missing server HTML costs nothing.
When to fix the component instead
Often the better fix is to make the component SSR-safe and keep a normal directive:
// src/components/ThemeLabel.tsx
import { useEffect, useState } from 'react';
export default function ThemeLabel() {
const [theme, setTheme] = useState<'light' | 'dark'>('light');
useEffect(() => {
setTheme(localStorage.getItem('theme') === 'dark' ? 'dark' : 'light');
}, []);
return <span>Theme: {theme}</span>;
}
useEffect only runs in the browser, so this renders on the server with a default and corrects itself after hydration. Use it with client:load or client:idle and the HTML is never empty. For libraries that break at import time, a dynamic import() inside the effect has the same effect.
What you give up
client:load / idle / visible |
client:only |
|
|---|---|---|
| Server HTML | Yes | No, only the fallback |
| Visible before JavaScript | Yes | No |
| Content indexable | Yes | Not reliably |
| Layout shift risk | Low | High without a sized fallback |
| Browser APIs during render | Must be guarded | Safe to use |
Don’t put headings, product details or anything you want indexed inside a client:only component. Render that content in Astro and keep only the interactive part client-only.
Timing
client:only loads and renders immediately on page load, like client:load. There’s no lazy variant, so for a heavy client-only widget far down the page, wrap it in a component that’s itself loaded later, or use a click-to-load pattern.
Our explainer on Astro client directives compares all five, and which client directive to use gives a decision checklist. For components in a Komal theme, see the folder structure docs, or start from one of our Astro themes, which render their content as HTML by default.
FAQ
What does client:only do in Astro?
It skips server-side rendering for a framework component and renders it only in the browser. The page ships the component’s JavaScript and, optionally, a fallback placeholder in its place.
Why does client:only need a framework name?
Astro normally detects the framework while rendering on the server. With client:only it never renders there, so you tell it which renderer to load, for example client:only="vue".
Is client:only bad for SEO?
For the content inside it, yes: that content isn’t in the HTML. Keep important text outside client-only components, and use them only for interactive or visitor-specific parts.