Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

linaria

> 前端框架
Open source

Zero-runtime CSS in JS library

12.3K stars0 likes1 views
WebsiteGitHub

About

Zero-runtime CSS in JS library

Zero-runtime CSS in JS library.


[![Build Status][build-badge]][build] [![Code Coverage][coverage-badge]][coverage] [![Version][version-badge]][package] [![MIT License][license-badge]][license]

![All Contributors][all-contributors-badge] [![PRs Welcome][prs-welcome-badge]][prs-welcome] [![Chat][chat-badge]][chat] [![Code of Conduct][coc-badge]][coc] [![Greenkeeper][greenkeeper-badge]][greenkeeper] [![Sponsored by Callstack][callstack-badge]][callstack]

[![tweet][tweet-badge]][tweet]

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
  • Supports atomic styles with @linaria/atomic

Why use Linaria

Learn how Airbnb improved both developer experience and web performance with Linaria

Installation

bash
npm install @linaria/core @linaria/react @wyw-in-js/babel-preset

or

bash
yarn add @linaria/core @linaria/react @wyw-in-js/babel-preset

Setup

Linaria is now built on top of wyw-in-js.dev. It supports various bundlers to extract the CSS at build time. To configure your bundler, check the following guides on the wyw-in-js.dev site:

  • webpack
  • esbuild
  • Rollup
  • Vite
  • Svelte

See Configuration to customize how Linaria processes your files.

Stability

Linaria relies on WyW (@wyw-in-js/*) to evaluate your modules at build time and extract CSS. If you hit issues like slow builds, invalidation storms, or unexpected code being executed during the build, it’s usually related to the WyW evaluation model and how your modules are structured.

Linaria 8 requires Node.js >=22.12.0 (aligned with the WyW 2 / Oxc dependency graph). WyW 2 defaults to eval.strategy: "hybrid", so statically provable values are resolved before falling back to the evaluator for dynamic values.

If your build depends on evaluator-only side effects or exact CSS rule order ties, review the Linaria 8 migration notes in docs/MIGRATION_GUIDE.md.

See https://wyw-in-js.dev/stability for practical guidance and common pitfalls.

Syntax

Linaria can be used with any framework, with additional helpers for React. The basic syntax looks like this:

javascript
import { css } from '@linaria/core';
import { modularScale, hiDPI } from 'polished';
import fonts from './fonts';

// Write your styles in `css` tag
const header = css`
  text-transform: uppercase;
  font-family: ${fonts.heading};
  font-size: ${modularScale(2)};

  ${hiDPI(1.5)} {
    font-size: ${modularScale(2.5)};
  }
`;

// Then use it as a class name
<h1 className={header}>Hello world</h1>;

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:

javascript
import { styled } from '@linaria/react';
import { families, sizes } from './fonts';

// Write your styles in `styled` tag
const Title = styled.h1`
  font-family: ${families.serif};
`;

const Container = styled.div`
  font-size: ${sizes.medium}px;
  color: ${props => props.color};
  border: 1px solid red;

  &:hover {
    border-color: blue;
  }

  ${Title} {
    margin-bottom: 24px;
  }
`;

// Then use the resulting component
<Container color="#333">
  <Title>Hello world</Title>
</Container>;

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.

Demo

Documentation

  • Basics
  • API and usage
    • Client APIs
    • Server APIs
  • Configuration
  • Dynamic styles with css tag
  • Theming
  • Critical CSS extraction
  • Bundlers integration
    • webpack
    • Rollup
  • CLI
  • Linting
  • How it works
  • Example

Contributing

We appreciate any support in library development!

Take a look on Contributing docs to check how you can run Linaria in development mode.

Trade-offs

  • No IE11 support when using dynamic styles in components with styled, since it uses CSS custom properties

  • Dynamic styles are not supported with css tag. See Dynamic styles with css tag for alternative approaches.

  • Modules used in the CSS rules cannot have side-effects. For example:

    javascript
    import { css } from '@linaria/core';
    import colors from './colors';
    
    const title = css`
      color: ${colors.text};
    `;

    Here, there should be no side-effects in the colors.js file, or any file it imports. We recommend to move helpers and shared configuration to files without any side-effects.

Interoperability with other CSS-in-JS libraries

Linaria can work together with other CSS-in-JS libraries out-of-the-box. However, if you want to use styled components from Linaria as selectors in styled-components/emotion, you need to use @linaria/interop

Editor Plugins

VSCode

  • Syntax Highlighting - language-babel
  • Autocompletion - vscode-styled-components
  • Linting - stylelint

Atom

  • Syntax Highlighting and Autocompletion - language-babel

Webstorm

  • Syntax Highlighting & Autocompletion - webstorm-styled-components

Sublime Text

  • Syntax Highlighting & Autocompletion - Naomi, JSCustom (refer to document on how to turn on Styled Component syntax)
  • Linting - SublimeLinter-stylelint, LSP Stylelint

Recommended Libraries

  • gatsby-plugin-linaria – Gatsby plugin that sets up Babel and webpack configuration for Linaria.
  • polished.js - A lightweight toolset for writing styles in JavaScript.
  • craco-linaria - A Craco plugin that allows you to use Linaria without ejecting from a CRA.

Inspiration

  • glam
  • styled-components
  • css-literal-loader

Acknowledgements

This project wouldn't have been possible without the following libraries or the people behind them.

  • babel
  • stylis.js

Special thanks to @kentcdodds for his babel plugin and @threepointone for his suggestions and encouragement.

Made with ❤️ at Callstack

Linaria is an open source project and will always remain free to use. If you think it's cool, please star it . Callstack is a group of React and React Native geeks, contact us at [email protected] if you need any help with these or just want to say hi!

Like the project? ⚛️ Join the team who does amazing stuff for clients and drives React Native Open Source!

Sponsors

Contributors

Thanks goes to these wonderful people (emoji key):


Paweł Trysła


Satyajit Sahoo


Michał Pierzchała


Lucas


Alexey Pronevich


Wojtek Szafraniec


Anton Evzhakov


Tushar Sonawane


Ferran Negre


Jakub Beneš

Issues· 72 open

View all issuesOpen on GitHub
  • #708

    Support for responsive props

    feature: proposal 💬Updated Sep 14, 2026
  • #1460

    Add support for interpolation

    enhancement: proposal 💬needs: triage 🏷Updated Apr 4, 2026
  • #236

    React Native support

    needs: investigation 🔎feature: approved ✅core team 🧬Updated Jan 6, 2026
  • #1324

    Support merging CSS for more convenient reuse of CSS.

    needs: triage 🏷feature: proposal 💬Updated Nov 24, 2025
  • #244

    `fragment` tag for composition

    feature: proposal 💬core team 🧬Updated Nov 24, 2025
  • #1417

    Change `styled()` types so that it works with libraries like Framer Motion

    enhancement: proposal 💬needs: triage 🏷Updated Nov 24, 2025
  • #234

    Modifier classes

    needs: triage 🏷feature: proposal 💬Updated Nov 19, 2025
  • #409

    Conditional CSS with styled tag

    feature: proposal 💬platform: react 🛠️cat: extend syntax ✍core team 🧬Updated Nov 19, 2025
  • #1423

    [postcss-linaria] Allow for alias of `css` in config

    enhancement: proposal 💬needs: triage 🏷cat: modules aliasing 🔗Updated Nov 19, 2025
  • #1427

    Support `keyframes` and `createGlobalStyle` in "@linaria/react"

    needs: triage 🏷feature: proposal 💬Updated Aug 25, 2025

> Tags

TypeScriptcsscss-in-jscss-in-reactreact

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 28, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架