Skip to content

Production CSS inlining

Inlining puts the page's CSS in a <style> tag in the HTML instead of linking a stylesheet. In principle that removes one render-blocking stylesheet request from the critical path; frameworks without it (Waku, Ember) still link the built stylesheet.

01 / 14First-paint leverOne of 7 features that affect first paint, the moment the browser first draws content. Together they are worth 14 of the 28 points.

Labels across 23 frameworks

  • 1st-party8
  • Experimental3
  • Third-party0
  • Manual12
  • of 23

Overview

Quoted text uses the source document's own marks: ✅ means 1st-party, 🧪 means Experimental or Third-party, and 🔧 means Manual.

We tested this feature in 15 Books ports. 14 passed; TanStack (Solid) failed (marked ✗). Each framework's card below shows what its test saw. How we test labels.

Labels record what each framework's documentation says it provides. They are not performance measurements. How the labels are assigned.

How to enable it, by framework

One card per framework, in the same order on every feature page. Where a framework has no built-in support (Manual), a short example shows how to build it yourself.

Next

Experimental1 ptOverview

Set experimental.inlineCss: true in next.config.ts (documented as experimental). One flag.

const nextConfig: NextConfig = {
  experimental: {
    inlineCss: true,
  },
};

From this repo's next-books/next.config.ts (other options omitted).

Nuxt

1st-party2 ptsOverview

Set features.inlineStyles: true, but only on this repo's nuxt-books-optimized-max branch; the plain optimized build leaves the global stylesheet linked.

export default defineNuxtConfig({
  features: {
    // Production SSR embeds entry and component CSS in the HTML.
    inlineStyles: true,
  },
});

From this repo's nuxt-books/nuxt.config.ts (nuxt-books-optimized-max branch).

SvelteKit

1st-party2 ptsOverview

Set inlineStyleThreshold high enough (e.g. Number.POSITIVE_INFINITY; the docs define it as the max CSS file length in UTF-16 code units) in vite.config.ts. One line, but you have to know it exists.

sveltekit({
  inlineStyleThreshold: Number.POSITIVE_INFINITY,
})

From this repo's svelte-books/vite.config.ts (optimized branch).

There is no first-party production inlining flag documented in the styling and assets docs (Solid 2 start mode, this port's stack; production output is <link rel="stylesheet"> tags) or in the archived SolidStart v2 CSS and styling docs, so you wire it yourself: import the stylesheet with ?inline (a Vite CSS feature) and render it in a <style> tag.

import appCss from "./app.css?inline";
// ...
<NoHydration>
  <style>{import.meta.env.SSR ? appCss : ""}</style>
</NoHydration>

From this repo's solid-books/src/Document.tsx (optimized branch). NoHydration keeps the CSS string out of the client bundle.

server.build.inlineCss (experimental) inlines manifest CSS. This port does not use it; it imports the CSS with ?inline and passes it through head().

import appCss from '../styles.css?inline'
// ...
export const Route = createRootRoute({
  head: () => ({
    styles: [{ children: appCss }],
  }),
})

From this repo's tanstack-books/src/routes/__root.tsx (optimized branch).

The same server.build.inlineCss flag exists. This port does not use it; src/routes/__root.tsx imports app.css?inline and passes it through head().

import appCss from "../app.css?inline";
// ...
head: () => ({
  styles: [{ children: appCss }],
}),

From this repo's tanstack-solid-books/src/routes/__root.tsx (optimized branch).

Our feature test turned the flag on in the 2.0.0-rc.8 port. The page got an inline <style> with the route's CSS, but the hashed route stylesheet (/assets/css-inlining-*.css) was still linked as a render-blocking <link rel="stylesheet">. The guide says the flag replaces manifest-managed stylesheet links with one inline <style> tag, so on this release line the flag only half works. The label stays 🧪 because the flag is documented as experimental.

Pracht

1st-party2 ptsOverview

Set inlineCss: true on the @pracht/vite-plugin options.

plugins: [pracht({ adapter, inlineCss: true })],

From this repo's pracht-books/vite.config.ts (optimized branch; other plugin options omitted).

Waku

Manual0 ptsOverview

Nothing to enable, and no first-party inlining is documented; the HTML links the built stylesheet (styling docs, migration guide on CSS).

Code example

In the root layout, import the stylesheet with Vite's ?inline query instead of as a side effect. Render it as a React 19 <style> with href and precedence, and React hoists it into <head>. The CSS string also travels in the RSC payload, so keep it small.

// src/pages/_layout.tsx
import appCss from '../styles.css?inline'; // was: import '../styles.css';
// …
export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    <>
      <title>Waku Books</title>
      <style href="app-css" precedence="default">{appCss}</style>
      {/* … */}
    </>
  );
}

Ember

Manual0 ptsOverview

Nothing to enable. The Vite guide covers build setup only; no first-party inlining is documented; index.html links /app/styles/app.css, and the optimized branch does not change that.

Code example

The port's build step already rewrites the HTML template. Extend it to swap the built stylesheet <link> for a <style> tag. The Node, Vercel, Netlify and Cloudflare deploys all use that template, so they all get the inlined CSS.

// scripts/prepare-server-template.mjs
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';

const root = process.cwd();
const clientIndex = resolve(root, 'dist/client/index.html');
const serverTemplate = resolve(root, 'dist/server/template.html');

let html = await readFile(clientIndex, 'utf8');
const link = html.match(/<link[^>]+href="(\/assets\/[^"]+\.css)"[^>]*>/);
if (link) {
  const css = await readFile(resolve(root, 'dist/client', link[1].slice(1)), 'utf8');
  html = html.replace(link[0], `<style>${css}</style>`);
}

await mkdir(resolve(root, 'dist/server'), { recursive: true });
await writeFile(serverTemplate, html);
await rm(clientIndex);

Astro

1st-party2 ptsOverview

build.inlineStylesheets: 'always' | 'auto' | 'never' (stable, astro@2.6.0+). Default auto inlines styles under 4kB and links larger ones; 'always' inlines all. (configuration-reference, styling)

Code example

build.inlineStylesheets controls whether project CSS ships as <style> tags or linked files. 'always' inlines every stylesheet; the default 'auto' inlines only files under Vite's 4kB assetsInlineLimit.

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

export default defineConfig({
  build: {
    inlineStylesheets: 'always', // 'auto' (default) | 'never'
  },
});

Source: Astro: configuration reference, build.inlineStylesheets

No first-party CSS inlining documented; CSS is Vite's story (side-effect imports, links export with ?url, React 19 <link precedence>). Inline by hand, e.g. ?inline. (styling)

Code example

Import the stylesheet with Vite's ?inline query instead of the port's ?url, and render it in a <style> in the root Layout. The string also ships in the client bundle, so keep it small.

// app/root.tsx
import appCss from './styles/global.css?inline'
// …
export const links: Route.LinksFunction = () => [
  { rel: 'icon', href: '/icon.svg', type: 'image/svg+xml' },
  // no { rel: 'stylesheet' } entry: the CSS is inlined below
]

export function Layout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <Meta />
        <Links />
        <style dangerouslySetInnerHTML={{ __html: appCss }} />
      </head>
      {/* … */}
    </html>
  )
}

Source: Vite: disabling CSS injection

Qwik City

1st-party2 ptsOverview

A global stylesheet under 10KB is inlined automatically in production; larger files load separately. useStyles$ / useStylesScoped$ are lazy-loadable. (styles)

Code example

Import the global stylesheet in root.tsx. In production Qwik inlines it when it is under inlineStylesUpToBytes (20 KB by default). Component styles registered with useStylesScoped$ load only with the component.

// src/root.tsx
import { component$ } from '@builder.io/qwik'
import { QwikCityProvider, RouterOutlet } from '@builder.io/qwik-city'
import { RouterHead } from './components/router-head/router-head'

import './styles/global.css' // inlined in production if < 20 KB (inlineStylesUpToBytes)

export default component$(() => (
  <QwikCityProvider>
    <head><meta charset="utf-8" /><RouterHead /></head>
    <body><RouterOutlet /></body>
  </QwikCityProvider>
))
// src/components/card/card.tsx
import { component$, useStylesScoped$ } from '@builder.io/qwik'
import styles from './card.css?inline'

export const Card = component$(() => {
  useStylesScoped$(styles)
  return <div class="card">…</div>
})

Source: Qwik: Styling

Angular (SSR)

1st-party2 ptsOverview

optimization.styles.inlineCritical defaults to true; critical CSS is inlined and the rest loads async. On in the default production config. (workspace-config, build)

Code example

Critical CSS inlining is part of the production optimization setting. Angular inlines the CSS the first page needs and loads the rest of the stylesheet async.

// angular.json
{
  "projects": {
    "books": {
      "architect": {
        "build": {
          "builder": "@angular/build:application",
          "configurations": {
            "production": {
              "optimization": {
                "scripts": true,
                "styles": { "minify": true, "inlineCritical": true },
                "fonts": true
              }
            }
          }
        }
      }
    }
  }
}

Source: Angular: Workspace configuration

Marko

Manual0 ptsOverview

<style> is bundled and loaded once; no inlining option documented (Vite ?inline would be by hand). No first-party CSS inlining documented. (styling)

Code example

You replace the layout's side-effect CSS import with a Vite ?inline import, then write it out with <html-style>. The port uses the same $!{…} form for its theme script in <html-script>.

// src/routes/+layout.marko
import css from "../styles.css?inline"   // was: import "../styles.css"

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    // emitted as a literal <style> in the streamed HTML; no stylesheet <link>
    <html-style>$!{css}</html-style>
    // …
  </head>
  <body>
    <${input.content}/>
  </body>
</html>

Source: Vite: disabling CSS injection

Fresh

Manual0 ptsOverview

No first-party CSS inlining documented. Vite bundles CSS imported from client.ts; a per-route css export adds stylesheets. A Vite ?inline import would be hand-wired (not found in the Fresh docs). (vite, file-routing)

Code example

You import the stylesheet with Vite's ?inline suffix in _app.tsx and render it in a <style> tag. Drop the import from client.ts so Vite stops adding the <link>.

// routes/_app.tsx
import globalCss from "../assets/global.css?inline";
import { define } from "../utils.ts";

export default define.page(function App({ Component }) {
  return (
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        {/* _app.tsx is server-only, so the CSS string never reaches an island bundle */}
        <style dangerouslySetInnerHTML={{ __html: globalCss }} />
        {/* … */}
      </head>
      <body f-client-nav>{/* … */}</body>
    </html>
  );
});

// client.ts
// import "./assets/global.css";  ← removed, or the <link> comes back

Source: Vite: disabling CSS injection

Analog

Manual0 ptsOverview

No first-party CSS inlining documented. Analog builds with Vite and its index.html links src/styles.css; Angular CLI's inlineCritical is an angular.json build option and is not listed among the analog() options. Inline by hand. (style-pipeline, migrating)

Code example

Analog has no inlining option, so inline the above-the-fold rules in index.html yourself and load the full stylesheet without blocking render.

<!-- index.html -->
<head>
  <base href="/" />
  <!-- hand-picked rules for the header and first row of cards -->
  <style>
    body { margin: 0; font-family: system-ui, sans-serif; }
    .site-header { height: 56px; display: flex; align-items: center; }
  </style>
  <!-- the rest loads async: applied once it arrives -->
  <link rel="stylesheet" href="/src/styles.css" media="print" onload="this.media='all'" />
  <noscript><link rel="stylesheet" href="/src/styles.css" /></noscript>
</head>

Source: Analog: Migrating an Angular app

Vike

Manual0 ptsOverview

No first-party CSS inlining documented; Vike injects <link rel="stylesheet"> tags for a page's CSS. injectFilter() only moves or drops injected tags. Inline by hand, for example with a Vite ?inline import. (preloading)

Code example

Import the critical stylesheet with Vite's ?inline query and print it in a <style> tag from +Head. Vike does not inject a <link> for a CSS file imported this way.

// pages/+Head.tsx
import criticalCss from './critical.css?inline'

export function Head() {
  return <style dangerouslySetInnerHTML={{ __html: criticalCss }} />
}

Source: Vite: Disabling CSS injection into the page · Vike: Preloading

No first-party CSS inlining documented; the Document links a stylesheet imported with ?url (<link rel="stylesheet" href={styles} />). Inline by hand. (tailwind, documents)

Code example

Import the stylesheet with Vite's ?inline query instead of ?url, and write it into a <style> in the Document. The Document renders only on the server, so the CSS string does not ship in a client bundle.

// src/app/Document.tsx
import styles from "./styles.css?inline"; // was: import styles from "./styles.css?url";

export const Document: React.FC<{ children: React.ReactNode }> = ({ children }) => (
  <html lang="en">
    <head>
      <meta charSet="utf-8" />
      <title>RedwoodSDK App</title>
      {/* was: <link rel="stylesheet" href={styles} /> */}
      <style dangerouslySetInnerHTML={{ __html: styles }} />
      <link rel="modulepreload" href="/src/client.tsx" />
    </head>
    <body>
      {children}
      <script>import("/src/client.tsx")</script>
    </body>
  </html>
);

Source: RedwoodSDK: Tailwind CSS · Vite: disabling CSS injection

Remix 3

1st-party2 ptsOverview

Styles written with the css(...) mixin from remix/component are collected during server rendering, deduplicated and emitted as <style data-rmx-style> tags in the document head. Global stylesheets added with <link rel="stylesheet"> and assets.getHref() stay linked files. (rendering-ui, component)

Code example

Styles written with css(...) and applied through the mix prop are collected during server rendering. Remix dedupes them and writes them into <style data-rmx-style> tags in the document head.

// app/ui/book-card.tsx
import { css } from "remix/component";
import type { Handle } from "remix/component";

export function BookCard(handle: Handle<{ title: string; author: string }>) {
  return () => (
    <article
      mix={css({
        border: "1px solid #d6d6d6",
        borderRadius: "12px",
        padding: "1rem",
        "&:hover": { borderColor: "#6d28d9" },
        "@media (max-width: 40rem)": { borderRadius: 0 },
      })}
    >
      <h2>{handle.props.title}</h2>
      <p>{handle.props.author}</p>
    </article>
  );
}

Source: Remix: Rendering UI, styling with css

No first-party CSS inlining documented. The render API's assetTags.css is "Stylesheet links for <head>", and Pages mode inserts the same links. Inline by hand, for example with a Vite ?inline import. (ssr, handlers)

Code example

Void has no option to inline CSS, so import the stylesheet with Vite's ?inline query and print it in a <style> tag. Void does not add a <link> for a file imported this way. React 19 hoists the <style href precedence> tag into <head>.

// pages/about.tsx
import criticalCss from './critical.css?inline'

export default function About() {
  return (
    <main>
      <style href="about-critical" precedence="default">{criticalCss}</style>
      <h1>About</h1>
    </main>
  )
}

Source: Vite: Disabling CSS injection into the page · Void: Head

No first-party CSS inlining documented. The render API's assetTags.css is "Stylesheet links for <head>", and Pages mode inserts the same links. Inline by hand, for example with a Vite ?inline import. (ssr, handlers)

Code example

Void has no option to inline CSS, so import the stylesheet with Vite's ?inline query and render it in a <style> element. Void does not add a <link> for a file imported this way. Vue templates cannot hold <style>, so render it with h().

<!-- pages/about.vue -->
<script setup lang="ts">
import { h } from 'vue'
import criticalCss from './critical.css?inline'

const InlineStyle = () => h('style', { id: 'about-critical', innerHTML: criticalCss })
</script>

<template>
  <main>
    <InlineStyle />
    <h1>About</h1>
  </main>
</template>

Source: Vite: Disabling CSS injection into the page · Vue: Render functions

Void (Svelte)

1st-party2 ptsOverview

Void itself has no CSS inlining (assetTags.css is "Stylesheet links for <head>"), but the Svelte compiler's <svelte:options css="injected" /> (or compilerOptions.css: 'injected' through voidSvelte({ svelte: { ... } })) puts each component's styles in an inline <style> in the server-rendered HTML. Global stylesheets imported from a layout stay linked files. Scored like Remix 3's css() mixin. (svelte-options, ssr, pages adapters)

Code example

Void has no CSS inlining of its own, but the Svelte compiler does: <svelte:options css="injected" /> puts the component's styles in an inline <style> in the server-rendered HTML. Set compilerOptions.css: 'injected' through voidSvelte({ svelte: { ... } }) to do it for every component. Global stylesheets imported from a layout stay linked files.

<!-- pages/about.svelte -->
<svelte:options css="injected" />

<main>
  <h1>About</h1>
</main>

<style>
  h1 { font-size: 2rem; }
</style>

Source: Svelte: svelte:options · Void: SSR

No first-party CSS inlining documented. The render API's assetTags.css is "Stylesheet links for <head>", and Pages mode inserts the same links. Inline by hand, for example with a Vite ?inline import. (ssr, handlers)

Code example

Void has no option to inline CSS, so import the stylesheet with Vite's ?inline query and print it in a <style> tag. Void does not add a <link> for a file imported this way.

// pages/about.tsx
import criticalCss from './critical.css?inline'

export default function About() {
  return (
    <main>
      <style id="about-critical" innerHTML={criticalCss} />
      <h1>About</h1>
    </main>
  )
}

Source: Vite: Disabling CSS injection into the page · Void: Head

Gotchas

  • A ?inline import puts the whole stylesheet in every HTML response, so it only suits small stylesheets.