Documentation
On this page
Install Cirth for Astro
Astro bundles every stylesheet a component imports. Import Cirth once, in a
layout every page uses, and it becomes global CSS for the document. The
frontmatter is the code between --- markers at the top of an .astro
file. Astro's build keeps Cirth's light-dark() colours.
Three steps: install, import it and check it.
1 Install #
npm install @cirthcss/cirth
pnpm add @cirthcss/cirth
yarn add @cirthcss/cirth
bun add @cirthcss/cirth
2 Import it #
In the frontmatter of the layout, for example src/layouts/Layout.astro:
---
import "@cirthcss/cirth";
const { title } = Astro.props;
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{title}</title>
</head>
<body>
<main class="container">
<slot />
</main>
</body>
</html>
A <style> block in a component is scoped by Astro and comes after Cirth, so
it wins without any specificity of its own.
3 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>
Run the app, 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.
Customization covers the --cirth-* properties; set
yours in a stylesheet the layout imports after Cirth. Package and builds lists the classless,
scoped and print entry points. Return to Framework guides
for another stack.