Skip to main content
Documentation
On this page

Install Cirth for PostCSS

PostCSS is a pipeline, not a bundler: it resolves an @import only with the postcss-import plugin, which inlines the file where the rule stands. Cirth needs nothing else from it.

Verified with PostCSS 8.5.28 on

Four steps: install, import it, add the plugin and check it.

1 Install #

Package manager
npm install @cirthcss/cirth postcss postcss-cli postcss-import
pnpm add @cirthcss/cirth postcss postcss-cli postcss-import
yarn add @cirthcss/cirth postcss postcss-cli postcss-import
bun add @cirthcss/cirth postcss postcss-cli postcss-import

2 Import it #

At the top of your stylesheet, say src/app.css:

@import "@cirthcss/cirth";

:root {
  --cirth-primary: #2563eb;
}

3 Add the plugin #

In postcss.config.js, postcss-import first, so later plugins see Cirth's rules:

module.exports = {
  plugins: [require("postcss-import")],
};

Autoprefixer, if your pipeline has it, adds two prefixed rules and changes nothing else. Then build:

npx postcss src/app.css -o dist/app.css

dist/app.css is the global stylesheet produced by the pipeline. Link that file from the shared document head, or pass it to the asset step that writes your application's final <link>.

4 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 after the @import. Package and builds lists the classless, scoped and print entry points. Return to Framework guides for another stack.

Search documentation

Type at least two characters to search.