API Reference

Lightning CSS

Rust-based CSS parser, transformer, and minifier with a Node API for transforming, bundling, and lowering modern CSS.

Official Documentation ↗
CompatibilityThis documentation covers version v1. Check the official docs for the latest API surface.

Installation

npmnpm install --save-dev lightningcss
pnpmpnpm add -D lightningcss

Methods

Overview

Lightning CSS is a Rust-based CSS parser and minifier with a Node API for transforming, bundling, and lowering modern CSS to target browsers. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • transform — Transforms a CSS buffer, applying targets and returning code plus referenced assets.
  • bundle — Resolves @import and inlines referenced CSS into a single output with assets.
  • transformStyleAttribute — Transforms inline style attribute declarations rather than full stylesheets.

Example

const { transform, browserslistToTargets } = require('lightningcss');

const out = transform({
  filename: 'a.css',
  code: Buffer.from('a { color: oklch(50% 0.1 200); }'),
  minify: true,
});

Notes

Transforms are driven by explicit browser targets, so quality depends on correct targets. The API works on Buffers rather than strings.

Verification

Transform a stylesheet using a modern color function and confirm it is lowered to a value the declared targets support.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://lightningcss.dev/docs.html · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:39.618Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

How do I specify browser targets?
Use browserslistToTargets(browserslist(...)) from the package, or pass a targets object with per-engine minimum versions and features.
Does Lightning CSS handle vendor prefixes?
Yes. It adds prefixes implied by your targets and by the features you enable, similar to Autoprefixer.
How are CSS modules supported?
Enable cssModules in transform options; the result includes an exports map from original class names to hashed names.