Styles & CSS Architecture
Dinou features a unified, zero-config styling pipeline supporting Tailwind CSS v4, CSS Modules in both Server and Client Components, and Global CSS with instant HMR and minified single-bundle extraction at /styles.css.
Styling in Dinou
Dinou provides built-in, out-of-the-box support for the modern CSS ecosystem across all three bundlers (esbuild, rollup, and webpack) and all five production runtimes (Node.js, Bun, Deno, Cloudflare Workers, and Netlify). Under the hood, Dinou orchestrates PostCSS, postcss-import, @tailwindcss/postcss, Autoprefixer, postcss-modules, and its internal CSS asset resolver to:
- Extract & minify all imported styles across Server Components, Client Components, layouts, error boundaries, and
not_foundroutes into a single production bundle emitted at.dinou/dist3/styles.css(served at/styles.css). - Guarantee RSC, SSR & Client parity for CSS Modules by compiling
*.module.csswith deterministic cryptographic[hash:base64]class names on both the Dual-Bundle server engine and client bundler—preventing hydration mismatches and Flash of Unstyled Content (FOUC). - Deliver zero-reload Hot Module Replacement (HMR) in development (including Webpack, Rollup, and Esbuild), updating
/styles.cssand newly added Tailwind utilities in place without losing React client state. - Resolve TypeScript path aliases & CSS assets (such as
@import "@/styles/tokens.css";andurl("@/assets/pattern.svg")) directly inside stylesheets.
tailwind.config.js required; configured natively via @theme and @utility blocks./styles.css bundle, eliminating FOUC across SSG, SSR, and static exports.Linking /styles.css
Because Dinou extracts all global styles, Tailwind utilities, and CSS Module rules into a unified stylesheet, link /styles.css explicitly in your root layout's <head>:
<link href="/styles.css" rel="stylesheet" precedence="default" />React 19 precedence Attribute
In React 19 and React Server Components (RSC), <link rel="stylesheet"> tags accept a precedence attribute (for example, precedence="default"). This instructs React to:
- Hoist Resources Automatically: React hoists the
<link>tag into the document<head>even if rendered inside a nested component or layout. - Synchronize Streaming & Suspense: React waits for the critical stylesheet to load before revealing streamed Suspense boundaries, preventing Flash of Unstyled Content (FOUC).
- Deduplicate Links: Multiple components rendering
/styles.csswith the same precedence emit only a single<link>element in the DOM.
Note on public/styles.css: If your application does not import any CSS files inside src/, you can place a static public/styles.css file and serve it directly at /styles.css. However, whenever any stylesheet is imported in src/, Dinou's compiled stylesheet bundle always takes precedence at /styles.css in both dinou dev and dinou build (ignoring public/styles.css with a console warning—rename static stylesheets in public/ to e.g. public/custom.css or import them from src/).
Tailwind CSS (v4 Engine)
Dinou ships with the official Tailwind CSS v4 engine via @tailwindcss/postcss. Tailwind v4 is CSS-first: no tailwind.config.js file is needed.
Enable Tailwind CSS across your entire application by importing it at the top of your root stylesheet (typically src/globals.css):
/* src/globals.css */
@import "tailwindcss";Custom @theme & Multi-Layout Setup
Define custom design tokens, colors, fonts, radii, and utilities directly in CSS using Tailwind v4's @theme and @utility directives:
/* src/globals.css */
@import "tailwindcss";
@theme {
--color-brand-primary: #3b82f6;
--color-brand-dark: #1e293b;
--font-display: "Inter", system-ui, sans-serif;
--radius-badge: 0.375rem;
}
/* Custom utility definitions */
@utility text-balance {
text-wrap: balance;
}
/* Base style overrides */
@layer base {
body {
@apply bg-slate-50 text-slate-900 dark:bg-slate-950 dark:text-slate-100 antialiased;
}
}Utilities such as bg-brand-primary, font-display, rounded-badge, and text-balance are generated automatically whenever they appear in your Server or Client Components.
Multi-Layout Tailwind Best Practice
/styles.css file, place @import "tailwindcss"; in one shared global stylesheet (such as src/globals.css) rather than repeating @import "tailwindcss"; across multiple nested layout CSS files. When using Tailwind's @apply or @variant inside secondary .css or .module.css files, use @reference "tailwindcss"; (or @reference "@/globals.css"; to access custom @theme tokens) without duplicating base reset layers.CSS Modules (*.module.css)
For component-scoped styling with zero selector collisions, name any stylesheet with the .module.css suffix. Dinou compiles CSS Modules seamlessly in both Server Components and Client Components across dinou dev, dinou build, and dinou export-static.
Server & Client Parity + Scoped Hashes
Dinou's shared createScopedName generator computes a deterministic Base64 cryptographic hash ([hash:base64]) from the local class name and the normalized file path relative to src/. Both the Dual-Bundle RSC/SSR server compiler and the client bundler produce the exact same class map:
/* src/components/card.module.css */
@reference "tailwindcss";
.card {
@apply rounded-xl p-6;
background-color: var(--card-bg, #ffffff);
border: 1px solid var(--border-color, #e2e8f0);
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}
.badge {
font-size: 0.75rem;
font-weight: 600;
color: #3b82f6;
}Import the default styles object directly in a Server Component (or in a "use client" component) without needing any client wrapper:
// src/components/card.tsx (Server Component by default)
import styles from "./card.module.css";
export function FeatureCard({ title, badge }: { title: string; badge: string }) {
return (
<article className={styles.card}>
<span className={styles.badge}>{badge}</span>
<h3 className="text-lg font-bold mt-2">{title}</h3>
</article>
);
}The rendered HTML outputs compact, collision-free classes such as class="B8B1e41-2H0_" identically during SSG/SSR and client hydration.
Global CSS, Third-Party Styles & Aliases
Dinou automatically discovers stylesheets imported anywhere in your route graph (note that unimported .css files in src/ are never bundled accidentally):
- Route & Boundary Entrypoints: Import
./globals.css(or additional stylesheets) insrc/layout.tsx,src/page.tsx,src/error.tsx, orsrc/not_found.tsx. - Third-Party
node_modulesStylesheets: Import package stylesheets such asimport "katex/dist/katex.min.css";directly inside either a Server Component or a Client Component (Dinou also honors the"style"export condition inpackage.json). - CSS
@importwith Path Aliases: Dinou wirespostcss-importto yourtsconfig.json/jsconfig.jsonpaths(with full support for JSONC comments and trailing commas):
/* src/globals.css — @import rules must precede @theme and other rules */
@import "tailwindcss";
@import "@/styles/tokens.css";
@import "@/styles/typography.css";CSS url(...) Assets & Fonts
Dinou's PostCSS pipeline distinguishes between static public/ URLs and bundled source/package assets across Esbuild, Rollup, and Webpack:
- Root-relative URLs (
url("/hero.webp")): Left untouched and served directly from yourpublic/directory. - Relative, aliased & package URLs (
url("./pattern.svg#grid"),url("@/assets/inter.woff2")): Resolved from disk (including inside@import-inlined partials andnode_modulesfonts), hashed, and emitted to/assets/<name>-<hash>.<ext>with immutable production caching while preserving SVG#fragmentidentifiers.
@font-face {
font-family: "BrandSans";
src: url("@/assets/fonts/brand-sans.woff2") format("woff2");
font-weight: 400 700;
font-display: swap;
}
.hero-surface {
/* /noise.png -> served from public/noise.png */
/* @/assets/grid.svg#mask -> emitted to /assets/grid-<hash>.svg#mask */
background-image: url("/noise.png"), url("@/assets/grid.svg#mask");
}Instant CSS Hot Module Replacement
During dinou dev, editing .css rules, .module.css properties, or adding new Tailwind utility classes in .tsx files incrementally updates /styles.css in memory and swaps the stylesheet via WebSocket with zero full-page reloads—preserving React client state, form inputs, open dialogs, and scroll positions. If you add or rename a class key in a .module.css file, Dinou also triggers an rsc-update automatically so Server Component class attributes stay synchronized.
TypeScript Declarations (dinou/env)
Built-in ambient type declarations for *.module.css, side-effect *.css imports, images, audio/video, and font files (*.woff2, *.woff, *.ttf, *.otf, *.eot) are provided via dinou/env.
Ensure a dinou-env.d.ts file exists at the root of your project:
/// <reference types="dinou/env" />Include dinou-env.d.ts and Dinou's generated route types in your tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"rootDirs": [
"src",
".dinou/routes"
],
"paths": {
"@/*": [
"./src/*"
]
},
"allowJs": true,
"skipLibCheck": true,
"noEmit": true,
"jsx": "react-jsx",
"strict": true,
"module": "ESNext",
"moduleResolution": "bundler"
},
"include": [
"src",
"dinou-env.d.ts",
".dinou/types/**/*.d.ts"
]
}Complete End-to-End Example
The following example combines a Server Component root layout, Tailwind v4 @theme tokens, a shared CSS Module, a Server Component page, and an interactive Client Component:
import type { LayoutProps } from "./dinou";
import "./globals.css"; // Imports Tailwind v4 & global tokens in a Server Component
export default function RootLayout({ children }: LayoutProps) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>My Dinou App</title>
{/* Unified stylesheet hoisted with React 19 precedence */}
<link href="/styles.css" rel="stylesheet" precedence="default" />
</head>
<body className="min-h-screen bg-slate-50 dark:bg-slate-950 text-slate-900 dark:text-slate-100 antialiased">
{children}
</body>
</html>
);
}@import "tailwindcss";
@theme {
--color-brand: #10b981;
--color-brand-hover: #059669;
--radius-panel: 1rem;
}
:root {
--card-bg: #ffffff;
--border-color: #e2e8f0;
}
@media (prefers-color-scheme: dark) {
:root {
--card-bg: #0f172a;
--border-color: #1e293b;
}
}
.custom-gradient {
background: linear-gradient(135deg, var(--color-brand) 0%, #f59e0b 100%);
}@reference "tailwindcss";
.card {
background-color: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: var(--radius-panel);
padding: 1.5rem;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}
.badge {
@apply inline-block text-xs font-bold uppercase tracking-wider;
color: var(--color-brand);
}import styles from "./card.module.css";
import { LikeButton } from "./like-button";
// Server Component using scoped CSS Modules + Tailwind utilities directly
export default function HomePage() {
return (
<main className="container max-w-2xl mx-auto py-12 px-4 space-y-6">
<header className="space-y-2">
<h1 className="text-3xl font-extrabold tracking-tight">
Styling with Dinou
</h1>
<p className="text-slate-600 dark:text-slate-400">
Combines Tailwind v4 utilities with universal CSS Modules.
</p>
</header>
<section className={styles.card}>
<span className={styles.badge}>Server Component Card</span>
<h2 className="text-xl font-bold mt-2">Zero Style Bleed</h2>
<p className="text-sm text-slate-500 dark:text-slate-400 mt-1">
Scoped classes render identically during RSC/SSR and client hydration.
</p>
<LikeButton />
</section>
</main>
);
}"use client";
import { useState } from "react";
import styles from "./card.module.css";
export function LikeButton() {
const [likes, setLikes] = useState(0);
return (
<button
type="button"
onClick={() => setLikes((n) => n + 1)}
className="mt-4 px-4 py-2 custom-gradient text-white rounded-lg font-medium shadow hover:opacity-90 transition"
>
Liked {likes} times • <span className={styles.badge}>Client Island</span>
</button>
);
}