Learn how to use CSS Modules in Bini.js for component-scoped styling.
CSS Modules let you write component-scoped CSS without worrying about class name conflicts. Vite processes .module.css files automatically - no configuration needed.
.module.css is processed as a CSS Module. Class names inside it are rewritten to be unique to that file.Create a new project with CSS Modules using the --css-modules flag:
Or run the interactive prompt and choose CSS Modules for styling:
Or combine with TypeScript:
Create a .module.css file next to your component and import it:
Vite rewrites every class name so it is unique to this file. The same .button in another module never collides:
Combine multiple CSS Module classes using template literals:
clsx or classnames library makes conditional class composition cleaner.Install clsx for cleaner conditional classes:
CSS Modules are locally scoped by default. Use :global to target global selectors:
composes copies the styles of one class into another, so you can share base styles without repeating declarations:
Use CSS variables for values that come from props. Set the variable inline, then read it in the module CSS with var():
Define animations in CSS Modules. @keyframes names are scoped to the module too, so they never collide with other files:
Write responsive styles with media queries:
A full-featured modal component using CSS Modules:
Plain CSS in Bini.js.
Utility-first styling with Tailwind.
Where components and CSS live in the app directory.
Where everything lives in a Bini.js app.
Learn how to use CSS Modules in Bini.js for component-scoped styling.
CSS Modules let you write component-scoped CSS without worrying about class name conflicts. Vite processes .module.css files automatically - no configuration needed.
.module.css is processed as a CSS Module. Class names inside it are rewritten to be unique to that file.Create a new project with CSS Modules using the --css-modules flag:
Or run the interactive prompt and choose CSS Modules for styling:
Or combine with TypeScript:
Create a .module.css file next to your component and import it:
Vite rewrites every class name so it is unique to this file. The same .button in another module never collides:
Combine multiple CSS Module classes using template literals:
clsx or classnames library makes conditional class composition cleaner.Install clsx for cleaner conditional classes:
CSS Modules are locally scoped by default. Use :global to target global selectors:
composes copies the styles of one class into another, so you can share base styles without repeating declarations:
Use CSS variables for values that come from props. Set the variable inline, then read it in the module CSS with var():
Define animations in CSS Modules. @keyframes names are scoped to the module too, so they never collide with other files:
Write responsive styles with media queries:
A full-featured modal component using CSS Modules:
Plain CSS in Bini.js.
Utility-first styling with Tailwind.
Where components and CSS live in the app directory.
Where everything lives in a Bini.js app.