Documentation
On this page
Install Cirth for Phoenix
A new Phoenix application builds its CSS with Tailwind and daisyUI, and its
JavaScript with esbuild. Without Tailwind, esbuild bundles CSS too, so Cirth
is one import in app.js and one link in the root layout.
Six steps: start without Tailwind, install, import it, link it, write HTML and check it.
1 Start without Tailwind #
Generate the application with --no-tailwind:
mix phx.new my_app --no-tailwind
In an existing application, remove Tailwind's configuration, dependency and build steps as Phoenix's asset management guide describes.
2 Install #
From the project root, into assets/, where esbuild resolves packages:
npm install @cirthcss/cirth --prefix assets
3 Import it #
At the top of assets/js/app.js:
import "@cirthcss/cirth";
esbuild writes every stylesheet that app.js imports to a separate file
beside the script: priv/static/assets/js/app.css.
4 Link it #
In lib/my_app_web/components/layouts/root.html.heex, link that file in
place of default.css, the daisyUI styles a project made without Tailwind
ships so that its generated components are not unstyled:
<link phx-track-static rel="stylesheet" href={~p"/assets/js/app.css"} />
default.css itself can then be deleted. esbuild keeps Cirth's
light-dark() colours as they are, so there is no CSS target to set.
5 Write HTML #
HEEx templates render ordinary elements:
<main class="container">
<article>
<header><h1>Hello, Phoenix</h1></header>
<label>
Email
<input type="email" name="email" required />
</label>
<footer><button type="submit">Subscribe</button></footer>
</article>
</main>
6 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 imported after Cirth. Package and builds lists the classless,
scoped and print entry points. Return to Framework guides
for another stack.