Jens Oliver Meiert

Use my latest work: latest tech book · latest non-tech book · latest optimization tool · latest defense tool

Syntax Highlighting: No Extra HTML for Code Blocks via Custom Highlights API and syntaxp

Published on Jul 23, 2026, filed under , . (Share this post, e.g., on Mastodon.)

You like to style code blocks but love minimal HTML? Then you’ve probably been waiting for the Custom Highlight API and getting rid of all the extra HTML that syntax-highlighting libraries used to inject.

While we’re waiting for solutions like Prism and highlight.js to reduce their DOM footprint and use the API, too, syntaxp is a small script that provides syntax highlighting, the modern way, today.

The way it works is you download, self-host, link the script, and that’s it:

<script src=/path/to/syntaxp.js defer></script>

This assumes you use conventional language-* classes on code elements, something which you often get with Markdown code fences.

If you’re not documenting what language a given code snippet uses, syntaxp offers auto-detection, which you can enable via data-autodetect:

<script src=/path/to/syntaxp.js defer data-autodetect></script>

This now gives you syntax highlighting, the minimalist (and Custom Highlight API) way:

syntaxp and a random HTML snippet in light mode.
syntaxp light.
syntaxp and another random HTML snippet in dark mode.
syntaxp dark.

If you want to see this in action, you already do: The syntax highlighting on meiert.com—like the HTML snippets on this page—as well as on frontenddogma.com and iadefensa.com is done via syntaxp 🙂

Have questions or suggestions about this? Check the documentation for context and details, and, as always, please file an issue for any problem you spot or suggestion you have. And, likewise as always, if you or your org gets value out of this, please do support my work financially (if only by learning or teaching with my books). I do the same supporting other peers. Cheers!

About Me

Jens Oliver Meiert, on March 2, 2026.

I’m Jens (long: Jens Oliver Meiert), and I’m an engineering lead, guerrilla philosopher, and indie publisher. I’ve worked as a technical lead and engineering manager at various companies, including Google; I’m an open-source developer and a contributor to web standards (like HTML, CSS, WCAG); and I write and review books for O’Reilly and Frontend Dogma.

I love trying things, not only in web development and engineering management, but also with respect to politics and philosophy. Here on meiert.com I talk about some of my experiences and perspectives. (Please share feedbackinterpret charitably, keep it friendly, but do be critical.)