Skip to main content
Documentation
On this page

Install Cirth for Next.js

In the App Router, global CSS is imported from the root layout. Cirth is one import there, plus a browser list so Next does not rewrite its colours.

Verified with Next.js 16.3.8 on

Five steps: install, import it, declare Cirth's browsers, write HTML and check it.

1 Install #

Package manager
npm install @cirthcss/cirth
pnpm add @cirthcss/cirth
yarn add @cirthcss/cirth
bun add @cirthcss/cirth

2 Import it #

At the top of app/layout.js (or layout.tsx):

import "@cirthcss/cirth";

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  );
}

Drop the starter's globals.css import, or keep it after Cirth's for your own rules.

3 Declare Cirth's browsers #

Next.js compiles CSS for browsers older than Cirth supports. That process rewrites light-dark() colours. The page can still follow the system theme, but a data-theme region may fail to force the other colour scheme. Set Next.js to Cirth's browser floor below. Compatibility explains the transformation and its limits.

Next.js reads this browserslist from package.json:

{
  "browserslist": [
    "chrome >= 123",
    "edge >= 123",
    "firefox >= 130",
    "safari >= 18.2",
    "ios_saf >= 18.2"
  ]
}

4 Write HTML #

Server and client components render ordinary elements, and Cirth styles them:

export default function Page() {
  return (
    <main className="container">
      <article>
        <header><h1>Hello, Next.js</h1></header>
        <p>Rendered on the server, styled by one stylesheet.</p>
        <footer><a href="/docs" role="button">Read the docs</a></footer>
      </article>
    </main>
  );
}

5 Check it #

Put this forced-dark region in a page or component that uses the global stylesheet:

<section data-theme="dark">
  <article>
    <p>Dark, whatever the system scheme is.</p>
  </article>
</section>

Build for production, then open the page while the system uses a light theme. A dark article proves that Cirth loaded and that data-theme="dark" is working. It remains dark when the system switches to a dark theme. If the article follows the surrounding page instead, the build rewrote Cirth's colours: check the browserslist above.

Customization covers the --cirth-* properties; set yours in a global stylesheet imported after Cirth. Package and builds lists the classless, scoped and print entry points. Return to Framework guides for another stack.

Vercel, the Vercel design, Next.js and related marks, designs and logos are trademarks or registered trademarks of Vercel, Inc. or its affiliates in the US and other countries.

Search documentation

Type at least two characters to search.