Documentation
On this page
Install Cirth for Laravel
Laravel builds its front end with Vite, and a new application imports
Tailwind from resources/css/app.css. Cirth takes Tailwind's place in that
file, and Vite gets one line of configuration.
Six steps: install, import it, configure Vite, load it in Blade, write HTML and check it.
1 Install #
npm install @cirthcss/cirth
pnpm add @cirthcss/cirth
yarn add @cirthcss/cirth
bun add @cirthcss/cirth
A new application also installs Tailwind, which styles the same elements from the opposite direction. Remove it:
npm uninstall tailwindcss @tailwindcss/vite
2 Import it #
Replace the contents of resources/css/app.css, Tailwind's @import,
@source and @theme, with:
@import "@cirthcss/cirth";
Rules of your own go after this line.
3 Configure Vite #
Remove the tailwindcss() plugin and its import from vite.config.js.
Vite compiles CSS for browsers older than Cirth supports. That process
rewrites light-dark() colours. The page can still follow the system theme,
but a data-theme region may fail to force the other colour scheme. Set
Vite to Cirth's browser floor below. Compatibility
explains the transformation and its limits.
Add build.cssTarget beside the Laravel plugin:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { bunny } from 'laravel-vite-plugin/fonts';
export default defineConfig({
build: {
cssTarget: ['chrome123', 'edge123', 'firefox130', 'safari18.2'],
},
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
fonts: [
bunny('Instrument Sans', {
weights: [400, 500, 600],
}),
],
}),
],
server: {
watch: {
ignored: ['**/storage/framework/views/**'],
},
},
});
The fonts and server entries are the starter's own and can stay.
4 Load it in Blade #
The @vite directive in your layout's <head> loads the built stylesheet,
or the development server's while npm run dev is running:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ $title ?? config('app.name') }}</title>
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body>
<main class="container">
@yield('content')
</main>
</body>
</html>
5 Write HTML #
Blade renders ordinary elements, and Cirth styles them:
@extends('layouts.app')
@section('content')
<article>
<header><h1>Hello, Laravel</h1></header>
<form method="POST" action="/subscribe">
@csrf
<label>
Email
<input type="email" name="email" required>
</label>
<button type="submit">Subscribe</button>
</form>
</article>
@endsection
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>
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 above.
Customization covers the --cirth-* properties; set
yours after the @import in resources/css/app.css. Package and builds lists the classless,
scoped and print entry points. Return to Framework guides
for another stack.