Skip to content

MicroLighter: Syntax Highlighter

Syntax highlighting for code blocks without the complicated markup, spans, classes, and bloated JavaScript, courtesy of Uncle Dave.

CSS-Tricks*
Aug 25, 20262 min read1 read
1

ere we go! Syntax highlighting for code blocks without the complicated markup, spans, classes, and bloated JavaScript, courtesy of Uncle Dave.

<pre> <code class="language-javascript">const answer = 42;</code> </pre>

MicroLighter is pretty much straight-up CSS leaning on Custom Highlights, using the ::highlight() pseudo… which is Baseline this year!

It accomplishes exactly every we need around here at CSS-Tricks — themes, line numbers, multiple language support, semantic markup, etc. — but without the added dependencies we rely on.

Chris made a custom WordPress block years and years ago that plugs in Prism.js. There’s certainly nothing wrong with Prism. It’s robust, supports a crap-ton of languages, is also super lightweight, and plenty battled-tested. Either way, I’ll certainly be looking at integrating this into our WordPress block.

It’s not that there isn’t any JavaScript involved. It’s that less of it is needed. And it leans so hard into modern CSS that it brings things like light-dark() support and custom properties along for the ride, meaning rolling your own theme is totally doable.

--syntax-background: light-dark(#ffffff, #0d1117); --syntax-foreground: light-dark(#24292f, #c9d1d9); --syntax-comment: light-dark(#6e7781, #8b949e); --syntax-keyword: light-dark(#cf222e, #ff7b72); --syntax-operator: light-dark(#24292f, #c9d1d9); --syntax-string: light-dark(#0a3069, #a5d6ff); --syntax-constant: light-dark(#0550ae, #79c0ff); --syntax-function: light-dark(#8250df, #d2a8ff); --syntax-type: light-dark(#8250df, #d2a8ff); --syntax-variable: light-dark(#953800, #ffa657); --syntax-property: light-dark(#0550ae, #79c0ff); --syntax-tag: light-dark(#116329, #7ee787); --syntax-selector: light-dark(#8250df, #d2a8ff); --syntax-inserted: light-dark(#116329, #7ee787); --syntax-deleted: light-dark(#cf222e, #ff7b72);

Plus, it’s super modular in the sense that you can snag the things you want à la carte: specific themes, just the languages you need to support, line numbers, a web component.

import "microlighter/micro-lighter-element.min.js"; <micro-lighter language="javascript" controls="copy" line-numbers> <pre> <code>const answer = 42;</code> </pre> </micro-lighter>

Reminds me too of this clever little web font that brings syntax highlighting along for the ride. I’ve been happily using that on my personal site for a while without any fuss.

Update (August 31, 2026): I just finished adding MicroLighter to this site in place of Prism. I haven’t benchmarked performance in terms of page speed, etc., but I can say that the savings is pretty significant. Where Prism came in at 35 KB raw (9.3 KB gzipped), MicroLighter is at 13.9 KB raw (5.2 KB gzipped). Not bad at all considering there are WordPress-specific customizations that had to be baked in.

Did you enjoy this article?

Recommend it — Standard Reader surfaces well-loved writing to more readers across the network.

Across the AtmosphereDiscussions