Islands, Styling, SEO & Deployment
Islands, styling, SEO, and deployment are all important topics to understand when building a real-world website with Astro. Let’s break them down one by one.
Astro Islands Architecture
Section titled “Astro Islands Architecture”This is one of the most important ideas in Astro, so let’s slow down and explain it simply.
By default, an Astro page is just plain HTML - no JavaScript at all. But sometimes, a small part of your page really does need to be interactive, like a counter button, or a like button, or a dropdown menu. Instead of turning your entire page into JavaScript just for that one small piece, Astro lets you keep everything else as plain HTML, and only sends JavaScript for that one small interactive piece.
That one small, interactive piece is called an island.
HTML (static) ├─ Header ├─ Article ├─ React Counter (hydrated) └─ FooterIn the picture above, the Header, Article, and Footer are all just plain HTML with no JavaScript. Only the “React Counter” part is an island - it gets its own small bit of JavaScript so it can actually work and respond to clicks.
How to Turn a Component Into an Island
Section titled “How to Turn a Component Into an Island”You just add a client: directive to the component, like this:
<Counter client:load />The Different Hydration Directives
Section titled “The Different Hydration Directives”“Hydration” simply means: adding JavaScript to a piece of HTML so it becomes interactive. Astro gives you a few different options for when this should happen:
client:load- load the JavaScript immediately, as soon as the page loadsclient:idle- load the JavaScript a little later, once the browser isn’t busy anymoreclient:visible- load the JavaScript only once this component actually scrolls into view on the screen
In simple words: use client:load for things that need to work right away. Use client:idle or client:visible for things that aren’t urgent, so your page loads faster overall.
Organizing CSS or Tailwind
Section titled “Organizing CSS or Tailwind”Plain CSS
Section titled “Plain CSS”If you’re writing your own CSS files, a clean way to organize them is:
styles/ ├─ base.css ├─ layout.css ├─ components.cssIn plain words: base.css holds your basic styles (fonts, colors, resets), layout.css holds styles for overall page structure, and components.css holds styles for individual reusable pieces, like buttons or cards.
If You’re Using Tailwind
Section titled “If You’re Using Tailwind”Tailwind works well with Astro because:
- It’s “utility-first,” meaning you style things using small, ready-made classes directly in your HTML.
- It doesn’t depend on JavaScript at all, so it doesn’t break Astro’s “ship less JavaScript” approach.
- It’s considered safe and well-supported for use inside Astro projects.
SEO Setup in Astro
Section titled “SEO Setup in Astro”SEO means making your website show up well in search engines like Google. Astro is naturally good at this, since it builds plain, fast-loading HTML by default - and search engines really like fast, simple HTML pages.
A good habit is to centralize your SEO tags inside your layout file, so every page automatically gets them.
<meta name="description" content={description} /><link rel="canonical" href={Astro.url} />In plain words: the description tag tells search engines (and people scrolling through search results) what your page is about. The canonical link tells search engines, “this is the official, main URL for this page,” which helps avoid confusion if the same content can be reached through more than one URL.
Open Graph Tags
Section titled “Open Graph Tags”Open Graph tags control how your page looks when it’s shared on social media (like a preview card on Twitter or Facebook).
<meta property="og:title" content={title} />You can add similar tags for og:description and og:image as well, so your shared links look complete and attractive.
Because Astro builds real HTML ahead of time (instead of relying on JavaScript to build the page later), search engines and social media crawlers can read your SEO and Open Graph tags right away, without any extra work. This is one of the biggest SEO advantages Astro has by default.
Forms and API Handling
Section titled “Forms and API Handling”A static page can still safely talk to a backend, by sending its form data to an API endpoint.
<form method="POST" action="/api/contact">export async function POST({ request }) { const data = await request.formData();}In plain words: the form on the page sends its data to /api/contact using a POST request. The matching POST() function (placed inside src/pages/api/contact.ts, for example) runs only on the server, reads the submitted form data, and can then safely do things like save it to a database or send an email. Since this code never runs in the browser, it’s a safe place to handle sensitive logic.
Deploying to Vercel
Section titled “Deploying to Vercel”Once your Astro site is ready, deploying it to Vercel is simple.
npm install @astrojs/vercelWhat you get with this:
- Little to no extra configuration needed
- Full support for SSR (Server-Side Rendering), if you’re using it
- Automatic builds, meaning Vercel rebuilds and redeploys your site whenever you push new changes
This adapter is what actually allows your Astro project (especially if you’re using SSR or hybrid mode) to run properly on Vercel’s servers.