# MicroLighter: A 2KB Syntax Highlighter Powered by CSS Custom Highlights

Original title: Introducing MicroLighter

> Hacker News story 49365326 · language: en · submitted 2026-08-19
> Web version: https://zeli.app/story/49365326
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 50 · by [tobr](<https://news.ycombinator.com/user?id=tobr>) · 💬 15
[original](<https://daverupert.com/2026/08/microlighter/>) · [HN discussion](<https://news.ycombinator.com/item?id=49365326>)

## Summary

Dave Rupert introduces MicroLighter, a tiny client-side syntax highlighter that leverages the CSS Custom Highlights API instead of injecting spans. It uses Textmate grammars for language support, auto-loads grammars on demand, and offers light-dark() themes. The core library focuses solely on highlighting, while extra features like line numbers are delegated to a custom element. This approach avoids DOM mutation and keeps the bundle size minimal.

## Key quote

> 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.

## HN discussion (15 comments)

### [piratebroadcast](<https://news.ycombinator.com/item?id=49366532>)

> I'm not trying to be rude or unappreciative, but it's kinda crazy to me that the website itself doesn't contain the demo of the thing? I see sample code to implement it on my own site, but the site itself doesn't seem to have any highlighting or I highlighted some text and didn't see anything unusual? Maybe it's just me, maybe I'm missing something here? I'd like to see an example of what a thing does before straight up installing the code on my website.

### [relativeadv](<https://news.ycombinator.com/item?id=49369379>)

> good to see dave still out there doing his thing

### [xigoi](<https://news.ycombinator.com/item?id=49365492>)

> Really cool! It’s a shame that the CSS Highlight API only allows changing the color and not the font.

---

## Cite

- Page: https://zeli.app/story/49365326
- Date: 2026-08-19
- Source: daverupert.com (https://daverupert.com/2026/08/microlighter/)
- Hacker News: https://news.ycombinator.com/item?id=49365326

## Other languages

- zh: https://zeli.app/zh/story/49365326 · markdown: https://zeli.app/zh/story/49365326.md
- ja: https://zeli.app/ja/story/49365326 · markdown: https://zeli.app/ja/story/49365326.md
- ko: https://zeli.app/ko/story/49365326 · markdown: https://zeli.app/ko/story/49365326.md
- de: https://zeli.app/de/story/49365326 · markdown: https://zeli.app/de/story/49365326.md
- es: https://zeli.app/es/story/49365326 · markdown: https://zeli.app/es/story/49365326.md
