Home

Awesome

CSS-Zero

Features

These benefits are in addition to the more general benefits of using CSS-in-JS:

Installation

Since CSS-Zero has no runtime, it can be installed purely as a devDependency:

npm install css-zero --save-dev

Setup

The simplest way to run CSS-Zero in a React application is using our Babel Macro:

import {css, styled} from 'css-zero/macro';

For applications created using Create React App (which supports both Babel Macros and CSS Modules out-of-the-box), no further setup or configuration is needed.

For usage with other front-end frameworks, CSS-Zero can be set up with our babel-plugin.

Syntax

The basic usage of CSS-Zero looks like this:

import {css, styles} from 'css-zero';

// Write your styles using the `css` tag
const blue = css`
  color: blue;
`;

const base = css`
  color: red;
  font-size: 16px;
`;

// then use the `styles` helper to compose your styles and generate class names
export default props => <div className={styles(base, props.isBlue && blue)} />;

      ↓ ↓ ↓ ↓ ↓ ↓ Compiles to  ↓ ↓ ↓ ↓ ↓ ↓

export default props => <div className={(props.isBlue ? "x1vong5g" : "x1dqz7z3") + " " + "x1e4w2a9"} />

// along with a the following .zero.css file:
.x1vong5g {color:blue}
.x1dqz7z3 {color:red}
.x1e4w2a9 {font-size:16px}

Demo

Edit CSS-Zero Create React App Example

Inspiration