serkankaya.
Türkçe sürüm
Let’s work together ↗

Astro SEO: A Fast, Crawlable Site Close to Lighthouse 100

How do you build an SEO-friendly site with Astro? Islands architecture, meta tags, sitemap, JSON-LD, image optimisation and what a Lighthouse score means.

Astro SEO is the setup that helps a site built with the Astro framework load fast, get crawled easily and be understood correctly by search engines. Because Astro turns pages into ready-made HTML by default, it gives you a good head start. You still have to set up the meta tags, canonical, sitemap, structured data and image settings yourself.

I built this site myself with Astro and publish it on Cloudflare Pages. I started out as a software developer and moved into SEO, so I am writing this from both sides. Below I explain why Astro is SEO-friendly, which settings are essential and what a Lighthouse score actually measures.

Why is Astro good for SEO?

Astro’s SEO advantage is that it serves content as ready-made HTML that can be read without running JavaScript. This approach is called static site generation (SSG): pages are turned into HTML files at build time, before any user requests them. Googlebot can process a page in two stages: it crawls the HTML first and renders the JavaScript later if needed. If the content is already in the initial HTML, there is no need to wait for the second stage.

A classic single page application (SPA) written in React or Vue works differently. The browser first receives an empty shell, and the content only appears after the JavaScript has been downloaded and executed. This setup increases both the rendering risk and the interaction delay. I covered this in more detail under the rendering heading of my what is technical SEO article.

Astro solves this problem with islands architecture. Islands architecture is an approach that leaves most of the page as static HTML and brings only the interactive parts to life, one by one. According to the Astro documentation, client-side JavaScript is loaded only for components marked with a client:* directive.[1]

Markdown / MDX Astro build Static HTML Googlebot and users
In Astro, content is turned into HTML at build time; the bot finds the content in the first response.

You also choose when a component loads. The Astro documentation describes three common directives as follows:[1]

DirectiveWhen does it load?Good use
client:loadAs soon as the page opensParts needed right away, such as a menu or cart
client:idleWhen the browser becomes idleChat bubble, secondary widget
client:visibleWhen the component enters the viewportCalculator or map further down the page

In addition, the server:defer directive turns a component into a “server island”. A server island renders personalised content on the server afterwards, without holding up the rest of the page.[1] The static page comes quickly from cache, and the dynamic part loads behind it.

How do you set up the basic SEO tags in Astro?

In Astro, the right place for SEO tags is a single layout component used by every page. The title, meta description, canonical and Open Graph tags are generated in this component from props. This prevents a tag from being forgotten on one page or written in a different format on another.

---
// src/layouts/Base.astro
const { title, description, noindex = false } = Astro.props;
const canonical = new URL(Astro.url.pathname, Astro.site).href;
---
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>{title}</title>
  <meta name="description" content={description} />
  {noindex
    ? <meta name="robots" content="noindex" />
    : <link rel="canonical" href={canonical} />}
  <meta property="og:title" content={title} />
  <meta property="og:description" content={description} />
  <meta property="og:url" content={canonical} />
</head>

In this example, the canonical URL is built from Astro.site and the page path. A canonical tag is an HTML tag that tells search engines the preferred address of a piece of content. I explained how duplicate URL problems arise in detail in what is a canonical tag.

Leaving out the canonical on a noindex page is a deliberate choice. Telling search engines both “do not index this” and “this is my preferred address” sends a contradictory signal.

A community package or your own layout?

Community packages such as astro-seo generate title, Open Graph and Twitter tags with a single component. On a small project, they speed things up. I prefer writing my own layout. Seeing directly which data each tag comes from saves time when debugging.

Community package

  • Quick start, little code
  • Ready-made Open Graph and Twitter tags
  • Depends on package updates
  • Limited flexibility for custom needs

Your own layout component

  • The source of every tag is visible
  • hreflang, JSON-LD and noindex in one place
  • No extra dependency
  • Initial setup takes a little longer
Both produce the right result; the difference is in control and ease of maintenance.

Sitemap, robots.txt and URL structure

In Astro, the sitemap is generated automatically by the official @astrojs/sitemap integration. According to the documentation, the integration works when the site field is set in the astro.config file. At the end of the build, sitemap-index.xml and sitemap-0.xml files are added to the output folder.[2]

// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';

export default defineConfig({
  site: 'https://example.com',
  trailingSlash: 'always',
  integrations: [
    sitemap({
      filter: (page) => !page.includes('/search/'),
    }),
  ],
});

The trailingSlash setting looks small, but it determines canonical consistency. With always, every internal address ends with /. When internal links, the sitemap and the canonical all use the same format, Google receives a single address signal.

The filter function keeps pages that should not be indexed, such as a search results page, out of the sitemap. Only pages that return 200, have a self-referencing canonical and are meant to be indexed belong in the sitemap.

For robots.txt, a public/robots.txt file is enough. Adding the sitemap URL at the end of the file makes it easier for bots to find the sitemap.

User-agent: *
Allow: /

Sitemap: https://example.com/sitemap-index.xml

How do you add structured data in Astro?

In Astro, structured data is added by printing a JSON-LD object into a script tag with set:html. JSON-LD is a data format that describes the entities on a page using the Schema.org vocabulary and that search engines can read directly. Using set:html ensures the object is written to the output without being broken by escape characters.

---
const schema = {
  '@context': 'https://schema.org',
  '@type': 'BlogPosting',
  headline: title,
  datePublished: pubDate.toISOString(),
  author: { '@type': 'Person', name: 'Author Name' },
};
---
<script type="application/ld+json" set:html={JSON.stringify(schema)} />

Combining this object with Content Collections makes the process safe. Content Collections is an Astro feature that validates the frontmatter fields of content files against a schema. A post with a missing title or an invalid date fails at build time and never goes live. I explained which schema type suits which page, with examples, in my schema markup guide.

How do you get a Lighthouse score of 100 in Astro?

Short answer

How do you get a Lighthouse score of 100 in Astro?

To get close to Lighthouse 100 in Astro, you need to reduce the JavaScript sent to the browser, give images dimensions and load the main image with priority. In the Lighthouse 10 score, the heaviest metrics are Total Blocking Time, LCP and CLS. The settings that fix these three metrics move the score the most.

  1. Remove unnecessary client:* directives and defer interaction with client:visible or client:idle
  2. Use images through the astro:assets Image component with width and height
  3. Keep the main image out of lazy loading and give it priority
  4. Serve fonts from your own server and use font-display: swap
  5. Inline small CSS files into the HTML
  6. Delay third-party tags until after consent and interaction

The Lighthouse performance score is a weighted average of five lab metrics. According to the Chrome documentation, the weights in Lighthouse 10 are as follows:[4]

MetricWeightRelated setting in Astro
Total Blocking Time (TBT)30%Few client:* directives, third-party scripts
Largest Contentful Paint (LCP)25%Main image priority, font and CSS loading
Cumulative Layout Shift (CLS)25%Image dimensions, font swapping
First Contentful Paint (FCP)10%Render-blocking CSS and scripts
Speed Index10%Overall loading speed of visible content

Reduce JavaScript

Total Blocking Time (TBT) is the total time the main thread is locked by long tasks. In Astro, what pushes TBT up is almost always unnecessary hydration. Hydration is the process of attaching JavaScript to static HTML in the browser to make a component interactive. Loading a card that only displays information with client:load sends code without any benefit.

Use images through the Image component

Astro’s Image component optimises the image and works out its dimensions by itself. According to the documentation, the component adds loading and decoding attributes and infers image dimensions automatically to avoid CLS.[3] The output is in WebP format by default.

---
import { Image } from 'astro:assets';
import cover from '../assets/cover.jpg';
---
<Image src={cover} alt="Cover image of a page built with Astro"
  loading="eager" fetchpriority="high" />

The main image in the first screen of a page is often the LCP element. Using loading="lazy" on this image delays LCP. Setting loading="eager" and fetchpriority="high" on the main image tells the browser to download this file first.

Control fonts and CSS

A font loaded from an external server such as Google Fonts means an extra connection and extra delay. Serving the font from your own domain and using font-display: swap lets text appear before the font arrives. The build.inlineStylesheets setting in the Astro config inlines small CSS files into the HTML and reduces extra render-blocking requests.

Does a Lighthouse score of 100 guarantee rankings?

A Lighthouse score of 100 does not guarantee rankings, because Lighthouse is a lab test while Google’s ranking systems look at real user experience and the relevance of the content. The Chrome documentation states clearly that a score of 100 is extremely challenging and not expected. According to the same source, moving a score from 99 to 100 takes about as much metric improvement as moving from 90 to 94.[4]

Google Search Central also states that Core Web Vitals are used in ranking. However, Google says it tries to show the most relevant content even when the page experience is poor. Good page experience makes a difference in searches where many helpful results compete.[5]

That is why I look at measurement in two layers. Lighthouse is a tool that gives fast feedback during development. The Core Web Vitals report in Search Console shows field data collected from the site’s real visitors. I gathered the LCP, INP and CLS thresholds and the ways to improve them in my improve Core Web Vitals article.

Which sites is Astro the right choice for?

Astro is the right choice for sites where content matters more than interaction. Blogs, corporate sites, service pages, documentation and landing pages for ad campaigns fall into this group. On these projects, most of the page is read; interaction is limited to a few forms or calculators.

The picture changes for applications dominated by user dashboards, real-time data and state that must persist across page transitions. In those cases, application-focused frameworks such as Next.js or Nuxt struggle less. Both can render HTML on the server, so they are good enough for SEO; the difference lies in how much JavaScript is shipped and in the development model.

On the performance marketing side, Astro has one more practical benefit. When landing pages open fast, fewer users leave after clicking an ad. Tracking tags are still necessary; setting up Google Tag Manager and consent management without hurting page speed is work that sits where software and marketing meet. I described this overlap in my marketing engineering article. For similar projects, you can look at my software development service page.

Astro SEO pre-launch checklist0/9

Summary

Astro gives you a strong foundation for SEO by producing ready-made HTML and shipping JavaScript only to the components that need it. What completes that foundation is your setup: tags gathered in a single layout, a consistent URL format, an automatic sitemap, JSON-LD and images with dimensions. Use the Lighthouse score as a guide during development, but measure success with field data in Search Console and with the quality of your content.

As a next step, run the checklist above on your own site. Then open the Core Web Vitals report in Search Console and note the page groups that fall below the “good” threshold. If you want the bigger picture of technical infrastructure, continue with my technical SEO guide. If you are curious about how I came to this work, take a look at my about page.

Key terms

Islands architecture
Islands architecture is a web architecture that serves most of a page as static HTML and brings only the components that need interaction to life, each with its own JavaScript. Astro implements it with client:* directives, which reduces the amount of code sent to the browser.
Hydration
Hydration is the process of attaching JavaScript in the browser to server-rendered static HTML so that a component becomes interactive. Hydrating a whole page keeps the main thread busy; Astro lowers that cost by hydrating only the selected components.
Static site generation
Static site generation (SSG) is the process of turning pages into ready-made HTML files at build time, before any user requests them. Because the server does not build the page on every request, responses are fast and search engine bots find the content directly in the HTML.
Content Collections
Content Collections is an Astro feature that validates Markdown, MDX or JSON content against a schema and lets you query it in a type-safe way. It catches missing titles, invalid dates and other SEO fields in frontmatter as errors during the build.

Frequently asked questions

Is Astro a good framework for SEO?

Yes, especially for content-heavy sites. Astro outputs ready-made HTML by default and only ships JavaScript to the components you mark. That makes it easier for Google to read the content without waiting for rendering, and it gives you a solid starting point for improving Core Web Vitals.

How do you create a sitemap in Astro?

Install the official @astrojs/sitemap integration and add it to your astro.config file. The integration needs your domain in the site field of the config to work. During the build, sitemap-index.xml and numbered sitemap files are generated automatically.

Does a Lighthouse score of 100 guarantee Google rankings?

No. Lighthouse is a lab measurement, while Google's ranking systems assess Core Web Vitals using real user data. According to Google, the most relevant content can still rank even when page experience is poor. Speed does not replace good content; it only supports it in competitive results.

Is Astro or Next.js better for SEO?

Both can render HTML on the server, so both are good enough for SEO when set up correctly. The difference lies in how much JavaScript is shipped and what the team needs. For content sites such as blogs, corporate sites and landing pages, Astro gets fast results with less code; for highly interactive applications, Next.js may be a better fit.

Do you need a plugin for meta tags in Astro?

No. Generating the title, description, canonical and Open Graph tags from props in a shared layout component is enough. Community packages such as astro-seo speed this up, but writing your own layout makes it easier to control where each tag comes from.

Sources

  1. Astro Docs: Islands architecture
  2. Astro Docs: @astrojs/sitemap
  3. Astro Docs: Images
  4. Chrome for Developers: Lighthouse performance scoring
  5. Google Search Central: Understanding page experience