Documentation
On this page
Install Cirth for Stimulus
Stimulus adds behaviour to HTML the server already rendered; it has no CSS step of its own. With Vite, the entry module is the JavaScript file loaded once to start the app; importing Cirth there makes it global CSS. Controllers can then change state through the HTML attributes Cirth reads.
Four steps: install, import it, set attributes, not classes and check it.
1 Install #
npm install @cirthcss/cirth @hotwired/stimulus
pnpm add @cirthcss/cirth @hotwired/stimulus
yarn add @cirthcss/cirth @hotwired/stimulus
bun add @cirthcss/cirth @hotwired/stimulus
2 Import it #
With Vite, at the top of the entry module, before the controllers:
import "@cirthcss/cirth";
import { Application } from "@hotwired/stimulus";
Set Vite's CSS target as in the Vite guide. In Rails, follow the Rails guide instead.
3 Set attributes, not classes #
A controller that marks a button busy while it saves:
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static targets = ["button"];
save() {
this.buttonTarget.setAttribute("aria-busy", "true");
}
}
<form data-controller="save">
<button type="submit" data-save-target="button" data-action="save#save">Save</button>
</form>
The same goes for aria-invalid on a field, aria-expanded on a toggle, and
open on a <details> or <dialog>.
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>
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 CSS target in the Vite guide.
Customization covers the --cirth-* properties; set
yours in a stylesheet imported after Cirth. Package and builds lists the classless,
scoped and print entry points. Return to Framework guides
for another stack.