Documentation
On this page
Install Cirth for Express
Express maps a directory to public URLs with express.static. Cirth's
package is finished CSS, so the server can expose it directly from
node_modules. Put its <link> in the shared layout or template head so
every rendered page loads it.
Four steps: install, serve it, link it and check it.
1 Install #
npm install @cirthcss/cirth express
pnpm add @cirthcss/cirth express
yarn add @cirthcss/cirth express
bun add @cirthcss/cirth express
2 Serve it #
Resolve the package's folder rather than writing the path out, so a workspace or a different install layout still finds it:
import path from "node:path";
import { fileURLToPath } from "node:url";
import express from "express";
const app = express();
const cirth = path.dirname(fileURLToPath(import.meta.resolve("@cirthcss/cirth")));
app.use("/css", express.static(cirth, { maxAge: "1y", immutable: true }));
import.meta.resolve returns the package's main file, dist/cirth.min.css,
so its folder holds every build. Use the long cache lifetime only with the
version in the URL, or drop the options.
3 Link it #
From whatever renders your pages, a template engine or a string:
<link rel="stylesheet" href="/css/cirth.min.css">
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 in a stylesheet loaded after Cirth's. Package and builds lists the classless,
scoped and print entry points. Return to Framework guides
for another stack.