# Introducing Microlighter

DevFeed: [Introducing Microlighter](<https://devfeed.tech/articles/introducing-microlighter-49217.md>)

Original publisher: [Read original article](<https://daverupert.com/2026/08/microlighter/>)

Author: Dave Rupert

Published: 2026-08-19T15:22:00Z

Content type: article

Language: en

Sources: [Dave Rupert](<https://devfeed.tech/sources/daverupert-com.md>)

Topics: [Syntax Highlighting](<https://devfeed.tech/topics/syntax-highlighting.md>), [CSS](<https://devfeed.tech/topics/css.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [HTML](<https://devfeed.tech/topics/html.md>), [Visual Studio Code](<https://devfeed.tech/topics/visual-studio-code.md>), [Jekyll](<https://devfeed.tech/topics/jekyll.md>), [Markdown](<https://devfeed.tech/topics/markdown.md>)

Tags: [blogging](<https://devfeed.tech/tags/blogging.md>), [code](<https://devfeed.tech/tags/code.md>), [css](<https://devfeed.tech/tags/css.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [jekyll](<https://devfeed.tech/tags/jekyll.md>), [markdown](<https://devfeed.tech/tags/markdown.md>), [projects](<https://devfeed.tech/tags/projects.md>), [syntax-highlighting](<https://devfeed.tech/tags/syntax-highlighting.md>), [vs-code](<https://devfeed.tech/tags/vs-code.md>)

## AI overview

An introduction to MicroLighter, a small client-side syntax highlighter built with the CSS Custom Highlights API. It uses TextMate language grammars, loads languages on demand, avoids DOM mutation, and supports human-readable themes.

## Source excerpt

I made a smol client-side syntax highlighter that uses the CSS Custom Highlights API called MicroLighter. I'll talk about why I made it in a bit but first I wanted to... ahem... highlight... some of the features. Zero-dependencies ~2kb minifed+gzipped Uses CSS ::highlight(token-name), not spans Leverages Textmate's language grammars Human-readable light-dark() themes All languages/grammars loaded on-demand Moves all non-highlight functionality to a <micro-lighter> custom element At some point I broke syntax highlighting on my Jekyll blog. I've used a handful of syntax highlighters over the years (Highlight.js, PrismJS, Rouge, Shiki, etc, etc) and I've felt the trade-offs between different client-side and server-side implementations. Faced with picking another, I knew I wanted to explore Bramus's technique of syntax highlighting with the CSS Custom Highlights API. There's some limitations with the CSS ::highlight() pseudo; no italics, no bold, no font swapping - but otherwise it's pretty cool syntax to idiomatically express "I want to highlight this token" via CSS instead of injecting spans everywhere. Using the Highlight API means I avoid any DOM mutation and the scope of the library shrinks down to: scan code blocks using regex patterns and send CSS.highlights.set(category, textRanges) to highlight the code blocks. I don't need much syntax highlighting on this site. Not all posts have code and my code samples are a whole fifteen lines long at best. My struggle is that I swap languages often. I'll do HTML, CSS, and JavaScript all in the same post. A little bash here, a little ruby there, some markdown as a treat. Using all those languages grew the complexity beyond the limits of my regex-fu, so I decided to lean on Textmate's established collections of patterns used by VS Code. And before I knew it, my little highlighter could do almost any language. Knowing I use different languages often, one principle I established was that all language grammars should be auto-loaded o