Skip to main content

What is styled-static?

Styled-static is a near-zero-runtime CSS-in-JS library for React 19+ that extracts all CSS at build time. Write styled-components syntax you already know, but get the performance of static CSS. What’s “zero”? CSS generation happens at build time (the expensive part). A minimal runtime (~45 bytes) handles className merging. Components are generated inline at build time.

Installation

Get started with styled-static in your React 19+ project

Quick Start

Build your first styled component in minutes

Core API

Explore the styled-components API you already know

How It Works

Understand the build-time transformation

Key Features

Static CSS

All CSS extracted at build time, no runtime stylesheet generation

Type-Safe

Full TypeScript support with proper prop inference

Familiar API

styled-components syntax you already know

Tiny Runtime

Minimal ~45 byte runtime for className merging only

Zero Dependencies

Uses native CSS features and Vite’s built-in tools

Inline Components

Components generated at build time, no runtime factories

Quick Example

Here’s a taste of what styled-static looks like:
import { styled } from '@alex.radulescu/styled-static';

const Button = styled.button`
  padding: 0.5rem 1rem;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;

  &:hover {
    background: #2563eb;
  }
`;

// Extend with additional styles
const PrimaryButton = styled(Button)`
  font-weight: bold;
`;

// Usage
<Button onClick={handleClick}>Click me</Button>
React 19+ Required — styled-static uses automatic ref forwarding, eliminating the need for forwardRef.

Why styled-static?

Native nesting, CSS variables, container queries—the gap between CSS and CSS-in-JS is smaller than ever. Modern browsers support everything we need.
Most CSS-in-JS libraries are obsolete, complex, or have large runtime overhead. We need something simpler and faster.
Better DX for writing CSS without runtime interpolation. Get the benefits of scoped CSS with a familiar API.
Minimal attack surface. Nothing to audit. Uses only native CSS features and Vite’s built-in tools.
95% native browser features + 5% build-time magic. No complex runtime, no CSS parsing overhead.

What We Don’t Do

Styled-static makes intentional trade-offs to stay simple and fast:
No runtime interpolation — Can’t write ${props => props.color}. Use variants, CSS variables, or data attributes instead.
React 19+ only — Uses automatic ref forwarding (no forwardRef needed).
Vite only — Uses Vite’s AST parser and virtual modules. No Webpack/Rollup support.
Each constraint removes complexity—no CSS parsing, no forwardRef wrapper, one great integration.

Core APIs at a Glance

Styled-static provides 10 core functions:
// Style elements
const Button = styled.button`padding: 0.5rem 1rem;`;

// Extend components
const Primary = styled(Button)`font-weight: bold;`;

// Get class string
const active = css`outline: 2px solid blue;`;

// Global styles
const GlobalStyle = createGlobalStyle`* { box-sizing: border-box; }`;

// Scoped keyframes
const spin = keyframes`from { transform: rotate(0deg); }`;

// Type-safe component variants
const Btn = styledVariants({
  component: 'button',
  css: css`padding: 0.5rem;`,
  variants: { size: { sm: css`font-size: 0.875rem;` } }
});

// Type-safe class variants
const badge = cssVariants({
  css: css`padding: 0.25rem;`,
  variants: { color: { blue: css`background: #e0f2fe;` } }
});

// Combine classes conditionally
<div className={cx('base', isActive && activeClass)} />

// Default attributes
const Input = styled.input.attrs({ type: 'password' })`padding: 0.5rem;`;

// Polymorphism
const LinkButton = withComponent(Link, Button);

Performance

Styled-static is designed for maximum performance:
ModuleMinifiedBrotli
runtime/index.js45 B50 B
This is a 98% reduction from traditional CSS-in-JS libraries like Emotion (~11 KB).

Next Steps

Install styled-static

Add styled-static to your project with npm, yarn, or bun

Follow the quickstart

Build your first styled component in 5 minutes

Read the API docs

Explore all available APIs and features

See comparisons

Compare styled-static with other CSS-in-JS libraries

Build docs developers (and LLMs) love