Skip to content

callstack/linaria

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1,009 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
Linaria

Zero-runtime CSS in JS library.


Build Status Code Coverage Version MIT License

All Contributors PRs Welcome Chat Code of Conduct Greenkeeper Sponsored by Callstack

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

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

or

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:

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 7 requires Node.js >=20 (WyW 1.x enforces this via engines).

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:

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:

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

Edit Linaria Demo

Documentation

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:

    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

Atom

Webstorm

Sublime Text

Recommended Libraries

Inspiration

Acknowledgements

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

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 hello@callstack.com 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

{callstack}

Servers.com

Contributors

Thanks goes to these wonderful people (emoji key):

Paweล‚ Trysล‚a
Paweล‚ Trysล‚a

๐Ÿ’ป ๐Ÿ“– ๐Ÿค”
Satyajit Sahoo
Satyajit Sahoo

๐Ÿ’ป ๐Ÿ“– ๐Ÿค”
Michaล‚ Pierzchaล‚a
Michaล‚ Pierzchaล‚a

๐Ÿ’ป ๐Ÿ“– ๐Ÿค”
Lucas
Lucas

๐Ÿ“–
Alexey Pronevich
Alexey Pronevich

๐Ÿ“–
Wojtek Szafraniec
Wojtek Szafraniec

๐Ÿ’ป
Anton Evzhakov
Anton Evzhakov

๐Ÿ’ป ๐Ÿค” ๐Ÿ“–
Tushar Sonawane
Tushar Sonawane

๐Ÿ“– ๐Ÿ’ก
Ferran Negre
Ferran Negre

๐Ÿ“–
Jakub Beneลก
Jakub Beneลก

๐Ÿ’ป ๐Ÿ“–
Oscar Busk
Oscar Busk

๐Ÿ› ๐Ÿ’ป
Dawid
Dawid

๐Ÿ’ป ๐Ÿ“–
Kacper Wiszczuk
Kacper Wiszczuk

๐Ÿ’ป ๐Ÿ“–
Denis Rul
Denis Rul

๐Ÿ’ป
Johan Holmerin
Johan Holmerin

๐Ÿ’ป ๐Ÿ“–
Gilad Peleg
Gilad Peleg

๐Ÿ“–
Giuseppe
Giuseppe

๐Ÿ’ป
Matija Marohniฤ‡
Matija Marohniฤ‡

๐Ÿ’ป ๐Ÿ“–
Stefan Schult
Stefan Schult

๐Ÿ’ป
Ward Peeters
Ward Peeters

๐Ÿ’ป
radoslaw-medryk
radoslaw-medryk

๐Ÿ’ป
ๆจๅ…ดๆดฒ
ๆจๅ…ดๆดฒ

๐Ÿ’ป
Dawid Karabin
Dawid Karabin

๐Ÿ“–
Chris Abrams
Chris Abrams

๐Ÿ’ป ๐Ÿ“– ๐Ÿค”
Jayphen
Jayphen

๐Ÿ’ป
c4605
c4605

๐Ÿ’ป
Toru Kobayashi
Toru Kobayashi

๐Ÿ’ป
Jakub Mazurek
Jakub Mazurek

๐Ÿ’ป
Joshua Nelson
Joshua Nelson

๐Ÿ’ป ๐Ÿค” ๐Ÿ“–
Tomasz Krzyลผowski
Tomasz Krzyลผowski

๐Ÿ’ป
Martin Schulze
Martin Schulze

๐Ÿ’ป
wmzy
wmzy

๐Ÿ’ป
Hyeseong Kim
Hyeseong Kim

๐Ÿ’ป
Martin Hochel
Martin Hochel

๐Ÿ’ป
Daniel Lo Nigro
Daniel Lo Nigro

๐Ÿ’ป
0xflotus
0xflotus

๐Ÿ’ป
Afzal Sayed
Afzal Sayed

๐Ÿ’ป
AijiUejima
AijiUejima

๐Ÿ’ป
Oleksii Vasyliev
Oleksii Vasyliev

๐Ÿ’ป
Alican ErdoฤŸan
Alican ErdoฤŸan

๐Ÿ’ป
Aman Kubanychbek
Aman Kubanychbek

๐Ÿ’ป
Andrew Gerard
Andrew Gerard

๐Ÿ’ป
Andrey Frolov
Andrey Frolov

๐Ÿ’ป
Benjamin Solum
Benjamin Solum

๐Ÿ’ป
Billy Kwok
Billy Kwok

๐Ÿ’ป
Christian Todd
Christian Todd

๐Ÿ’ป
David Peek
David Peek

๐Ÿ’ป
Denis Skiba
Denis Skiba

๐Ÿ’ป
Dima Kharitonov
Dima Kharitonov

๐Ÿ’ป
Gabriel Valfridsson
Gabriel Valfridsson

๐Ÿ’ป
Gitai
Gitai

๐Ÿ’ป
Hampus Kraft
Hampus Kraft

๐Ÿ’ป
Igor Sukharev
Igor Sukharev

๐Ÿ’ป
Ikko Ashimine
Ikko Ashimine

๐Ÿ’ป
Iman Mohamadi
Iman Mohamadi

๐Ÿ’ป
JB <codecorsair>
JB

๐Ÿ’ป
Jack Works
Jack Works

๐Ÿ’ป
James George
James George

๐Ÿ’ป
Jed Mao
Jed Mao

๐Ÿ’ป
Joe Lencioni
Joe Lencioni

๐Ÿ’ป
Joey Cozza
Joey Cozza

๐Ÿ’ป
Juan Ferreras
Juan Ferreras

๐Ÿ’ป
Kazuma Ebina
Kazuma Ebina

๐Ÿ’ป
Lars Kappert
Lars Kappert

๐Ÿ’ป
Luciano Mammino
Luciano Mammino

๐Ÿ’ป
Madhav Varshney
Madhav Varshney

๐Ÿ’ป
Malash
Malash

๐Ÿ’ป
Martijn Swaagman
Martijn Swaagman

๐Ÿ’ป
Matias Lahti
Matias Lahti

๐Ÿ’ป
Michael James
Michael James

๐Ÿ’ป
Michael Strobel
Michael Strobel

๐Ÿ’ป
Michaล‚ Chudziak
Michaล‚ Chudziak

๐Ÿ’ป
Mike
Mike

๐Ÿ’ป
Mike Stop Continues
Mike Stop Continues

๐Ÿ’ป
Mokshit Jain
Mokshit Jain

๐Ÿ’ป
Oleksandr Fediashov
Oleksandr Fediashov

๐Ÿ’ป
Paddy O'Brien
Paddy O'Brien

๐Ÿ’ป
Patrik Smฤ›lรฝ
Patrik Smฤ›lรฝ

๐Ÿ’ป
Pavel Udaloff
Pavel Udaloff

๐Ÿ’ป
Przemysล‚aw Bitkowski
Przemysล‚aw Bitkowski

๐Ÿ’ป
RiN
RiN

๐Ÿ’ป
Roman Sokhan
Roman Sokhan

๐Ÿ’ป
Seokmin Hong (Ray)
Seokmin Hong (Ray)

๐Ÿ’ป
Serge K Lebedev
Serge K Lebedev

๐Ÿ’ป
Sergey Korovin
Sergey Korovin

๐Ÿ’ป
Shreyas Sreenivas
Shreyas Sreenivas

๐Ÿ’ป
Sky Wickenden
Sky Wickenden

๐Ÿ’ป
Stanislav Panferov
Stanislav Panferov

๐Ÿ’ป
Ted Jenkins
Ted Jenkins

๐Ÿ’ป
Thanh Tran
Thanh Tran

๐Ÿ’ป
Thor Amorim
Thor Amorim

๐Ÿ’ป
tobenna
tobenna

๐Ÿ’ป
Tomas Carnecky
Tomas Carnecky

๐Ÿ’ป
Tsubasa1218
Tsubasa1218

๐Ÿ’ป
Turadg Aleahmad
Turadg Aleahmad

๐Ÿ’ป
Vitor Buzinaro
Vitor Buzinaro

๐Ÿ’ป
Mistereo
Mistereo

๐Ÿ’ป
Vladislav Kozulya
Vladislav Kozulya

๐Ÿ’ป
Yuhei Yasuda
Yuhei Yasuda

๐Ÿ’ป
Danil Kamyshov
Danil Kamyshov

๐Ÿ’ป
Sebastian Landwehr
Sebastian Landwehr

๐Ÿ’ป
everdimension
everdimension

๐Ÿ’ป
ptol
ptol

๐Ÿ’ป
roottool
roottool

๐Ÿ’ป
ryamaguchi0220
ryamaguchi0220

๐Ÿ’ป
simka
simka

๐Ÿ’ป
soso
soso

๐Ÿ’ป
Nikita Skovoroda
Nikita Skovoroda

๐Ÿ’ป
้ป„ๅฐๅฅ
้ป„ๅฐๅฅ

๐Ÿ’ป
iMoses
iMoses

๐Ÿ’ป
Jeremy Neander
Jeremy Neander

๐Ÿ’ป
Andy Parsons
Andy Parsons

๐Ÿ’ป
Platane
Platane

๐Ÿ“–
Tim Kutnick
Tim Kutnick

๐Ÿ“–
Dmitrii Pikulin
Dmitrii Pikulin

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Zero-runtime CSS in JS library

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors