lightningcss is a free, open source build & deployment project written in Rust and released under MPL-2.0. It has 7,677 GitHub stars, 301 forks and 428 open issues, and was last pushed 8 days ago. On this registry it ranks #21 of 59 tracked projects in Build & Deployment, with 5 head-to-head comparisons available. It gained 1 stars over the last 3 tracked days.

What is lightningcss?

Lightning CSS is an extremely fast CSS parser, transformer, bundler, and minifier written in Rust, built for front-end developers and build-tool authors who need to parse, lower, prefix, and minify CSS.

What it is

Lightning CSS is a CSS parser, transformer, bundler, and minifier written in Rust. It sits in the web build toolchain, used with Parcel, as a standalone library or CLI, or as a plugin with any other tool. It is built on the cssparser and selectors crates created by Mozilla and used by Firefox and Servo, which provide a general-purpose CSS parsing foundation, on top of which Lightning CSS implements support for all specific CSS rules and properties.

The problem it solves is CSS parsing and minification that is both fast and type-aware. Most other CSS parsers treat property values as an untyped series of tokens, so every transformer that wants to do something with a value must interpret it again, producing duplicate work and inconsistencies. Lightning CSS parses all values using the grammar from the CSS specification and exposes a specific value type for each property. In practice this replaces token-level CSS minifiers such as cssnano with a browser-grade parser that also handles vendor prefixing and syntax lowering against declared browser targets.

Key capabilities

  • Typed property values: all values are parsed against the CSS specification grammar, so each property exposes a specific value type instead of an untyped token stream.
  • Browser-grade parsing on the cssparser and selectors crates from Mozilla, the same foundation used by Firefox and Servo.
  • Minification that combines longhand properties into shorthands, merges adjacent rules with the same selectors or declarations when safe, collapses CSS transforms into a single matrix or the reverse when smaller, reduces calc() expressions, converts colors to shorter hex notation, minifies gradients and CSS grid templates, normalizes property value order, and removes default sub-values that browsers infer.
  • Vendor prefixing driven by a browser targets list, automatically adding and removing prefixes.
  • Opt-in browserslist configuration discovery to resolve browser targets and integrate with existing tools and config setups.
  • Syntax lowering for CSS Nesting, custom media queries, logical properties, Color Level 4 and Level 5 features including lab(), lch(), oklab(), oklch(), color(), color-mix() with display-p3 and xyz spaces, relative color syntax, hwb(), #rgba and #rrggbbaa hex, and percent syntax for opacity.
  • Selector and math lowering for :not and :lang with multiple arguments, :dir, :is, clamp(), round(), rem(), mod(), two-value overflow, place-items alignment shorthands, and media query range syntax.

Who uses it and how

  • Teams working in the Parcel ecosystem get Lightning CSS through their existing build setup.
  • Build-tool authors embed it as a standalone Rust library or as a plugin to bring parsing, prefixing, and minification into another tool.
  • Developers run it directly as a CLI for one-off parsing and minification of CSS files.
  • Projects with custom browser support matrices pass a browser targets list, or opt into browserslist discovery so existing config resolves targets.
  • Stylesheet authors writing newer CSS syntax rely on lowering to emit compatible output while keeping modern source syntax.

Getting started

The README describes using it with Parcel, as a standalone library or CLI, or via a plugin with any other tool. No package name, Docker image, compose file, or hosted option appears in the supplied facts.

How it compares

Among the tools named in the facts, the closest comparison points are cssnano, esbuild, and Parcel. In the README benchmarks on bootstrap-4.css, Lightning CSS takes 4.16ms and emits 143091 bytes against cssnano at 544.809ms and 159636 bytes, and on tailwind.css it takes 43.368ms and emits 1824130 bytes against cssnano at 2.198s and 1925626 bytes. The README notes that some compared tools perform unsafe optimizations that may change the behavior of the original CSS in favor of smaller file size, while Lightning CSS output should always behave identically to the input.

When to use it — and when not to

Choose it where CSS parsing, prefixing, and minification must be fast, type-aware, and behavior-preserving, and where a Rust library, CLI, or plugin fits the existing pipeline. A self-hoster operates a Rust or Node-based build step; the facts document no server, database, storage, or hosted service to run. Do not pick it expecting an install command or deployment guide in the README, expecting a bundled hosted option, or overlooking the 428 open issues, the MPL-2.0 licence, and a README excerpt that is feature-and-benchmark focused rather than setup focused.

project readme (upstream, from github) — read inline

⚡️ Lightning CSS

An extremely fast CSS parser, transformer, and minifier written in Rust. Use it with Parcel, as a standalone library or CLI, or via a plugin with any other tool.

performance and build size charts performance and build size charts

Features

  • Extremely fast – Parsing and minifying large files is completed in milliseconds, often with significantly smaller output than other tools. See benchmarks below.
  • Typed property values – many other CSS parsers treat property values as an untyped series of tokens. This means that each transformer that wants to do something with these values must interpret them itself, leading to duplicate work and inconsistencies. Lightning CSS parses all values using the grammar from the CSS specification, and exposes a specific value type for each property.
  • Browser-grade parser – Lightning CSS is built on the cssparser and selectors crates created by Mozilla and used by Firefox and Servo. These provide a solid general purpose CSS-parsing foundation on top of which Lightning CSS implements support for all specific CSS rules and properties.
  • Minification – One of the main purposes of Lightning CSS is to minify CSS to make it smaller. This includes many optimizations including:
    • Combining longhand properties into shorthands where possible.
    • Merging adjacent rules with the same selectors or declarations when it is safe to do so.
    • Combining CSS transforms into a single matrix or vice versa when smaller.
    • Removing vendor prefixes that are not needed, based on the provided browser targets.
    • Reducing calc() expressions where possible.
    • Converting colors to shorter hex notation where possible.
    • Minifying gradients.
    • Minifying CSS grid templates.
    • Normalizing property value order.
    • Removing default property sub-values which will be inferred by browsers.
    • Many micro-optimizations, e.g. converting to shorter units, removing unnecessary quotation marks, etc.
  • Vendor prefixing – Lightning CSS accepts a list of browser targets, and automatically adds (and removes) vendor prefixes.
  • Browserslist configuration – Lightning CSS supports opt-in browserslist configuration discovery to resolve browser targets and integrate with your existing tools and config setup.
  • Syntax lowering – Lightning CSS parses modern CSS syntax, and generates more compatible output where needed, based on browser targets.
    • CSS Nesting
    • Custom media queries (draft spec)
    • Logical properties
    • Color Level 5
      • color-mix() function
      • Relative color syntax, e.g. lab(from purple calc(l * .8) a b)
    • Color Level 4
      • lab(), lch(), oklab(), and oklch() colors
      • color() function supporting predefined color spaces such as display-p3 and xyz
      • Space separated components in rgb and hsl functions
      • Hex with alpha syntax
      • hwb() color syntax
      • Percent syntax for opacity
      • #rgba and #rrggbbaa hex colors
    • Selectors
      • :not with multiple arguments
      • :lang with multiple arguments
      • :dir
      • :is
    • Double position gradient stops (e.g. red 40% 80%)
    • clamp(), round(), rem(), and mod() math functions
    • Alignment shorthands (e.g. place-items)
    • Two-value overflow shorthand
    • Media query range syntax (e.g. `@media (width
performance and build size charts
$ node bench.js bootstrap-4.css
cssnano: 544.809ms
159636 bytes

esbuild: 17.199ms
160332 bytes

lightningcss: 4.16ms
143091 bytes


$ node bench.js animate.css
cssnano: 283.105ms
71723 bytes

esbuild: 11.858ms
72183 bytes

lightningcss: 1.973ms
23666 bytes


$ node bench.js tailwind.css
cssnano: 2.198s
1925626 bytes

esbuild: 107.668ms
1961642 bytes

lightningcss: 43.368ms
1824130 bytes

For more benchmarks comparing more tools and input, see here. Note that some of the tools shown perform unsafe optimizations that may change the behavior of the original CSS in favor of smaller file size. Lightning CSS does not do this – the output CSS should always behave identically to the input. Keep this in mind when comparing file sizes between tools.

Frequently asked questions

Is lightningcss free to use?

lightningcss is open source under the MPL-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does lightningcss do?

An extremely fast CSS parser, transformer, bundler, and minifier written in Rust.

What is lightningcss written in?

lightningcss is primarily written in Rust. Its source is publicly available at https://github.com/parcel-bundler/lightningcss, and it has 7,677 GitHub stars.