Linaria
Zero-runtime CSS in JS library.
Features
- Write CSS in JS, but with zero runtime, CSS is extracted to CSS files during build
- Familiar CSS syntax with Sass like nesting
- Use dynamic prop based styles with the React bindings, uses CSS variables behind the scenes
- Easily find where the style was defined with CSS sourcemaps
- Lint your CSS in JS with stylelint
- Use JavaScript for logic, no CSS preprocessor needed
- Optionally use any CSS preprocessor such as Sass or PostCSS
Installation
or
Setup
Linaria currently supports webpack and Rollup to extract the CSS at build time. To configure your bundler, check the following guides:
Or configure Linaria with one of the following integrations:
Optionally, add the @linaria
preset to your Babel configuration at the end of the presets list to avoid errors when importing the components in your server code or tests:
See Configuration to customize how Linaria processes your files.
Syntax
Linaria can be used with any framework, with additional helpers for React. The basic syntax looks like this:
You can use imported variables and functions for logic inside the CSS code. They will be evaluated at build time.
If you're using React, you can use the styled
helper, which makes it easy to write React components with dynamic styles with a styled-component like syntax:
Dynamic styles will be applied using CSS custom properties (aka CSS variables) and don't require any runtime.
See Basics for a detailed information about the syntax.