nishiki

Atomic CSS-in-JS for React

Warning

This library is experimental and not yet stable. The API and the generated class names may change.

Write styles where they are used, with a css prop, styled or css(), and keep them working with or without a build step.

  • No build step required. Rules are inserted through React's <style href precedence> hoisting, so styles work in Server Components and Client Components alike.
  • A compiler when you want one. The unplugin compiles literal styles with oxc at build time. Fully static styles are hoisted to module scope, so a render does no style work for them; anything that is not a literal keeps working at runtime.
  • Static CSS, split per chunk. With extract, compiled rules leave the JavaScript for static CSS. In Vite client, Rollup and Rolldown builds, each entry and lazily loaded chunk gets a stylesheet with only the rules it adds.
  • Predictable composition. Cascade layers order shorthands, longhands and nesting levels, so those win the same way whichever order their rules arrive in.

The example above is a live React island on this page, styled by the library itself. Its static rules were extracted to CSS when this site was built.

import { styled } from "nishiki";
import { useState } from "react";

const Button = styled("button", {
  padding: "8px 16px",
  border: "none",
  borderRadius: 6,
  background: "#1f6feb",
  color: "white",
  font: "inherit",
  cursor: "pointer",
  ":hover": { background: "#1158c7" },
  "@media (max-width: 600px)": { width: "100%" },
});

export default function Counter() {
  const [count, setCount] = useState(0);
  return (
    <div css={{ display: "grid", gap: 12 }}>
      <p css={{ margin: 0, color: count % 2 ? "crimson" : "seagreen" }}>
        Clicked {count} {count === 1 ? "time" : "times"}
      </p>
      <Button css={{ justifySelf: "start" }} onClick={() => setCount((c) => c + 1)}>
        Increment
      </Button>
    </div>
  );
}

Where next

  • Getting started: install the package and render your first styled component.
  • Styling API: the css prop, styled, css() and style objects.
  • Bundler setup: add the compiler to Vite, Rollup, Rolldown, webpack, Rspack, Rsbuild, esbuild, Bun, Farm, unloader or Next.js.
  • Extraction and CSS splitting: how rules become stylesheets, split per chunk or one per entry.