Syntax Highlighting: No Extra HTML for Code Blocks via Custom Highlight API and syntaxp
Published on Jul聽23, 2026, filed under tools, development. (Share this post, e.g., on Mastodon.)
You like to style code blocks but love minimal HTML? Then you鈥檝e 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鈥檙e 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 (and responsible) way, today.
The way it works is you download, self-host, link the script, and that鈥檚 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鈥檙e 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:

If you want to see this in action, you already do: The syntax highlighting on meiert.com鈥攍ike the HTML snippets on this page鈥攁s well as on frontenddogma.com and iadefensa.com is done via syntaxp聽馃檪 However, syntaxp ships with a demo page full of examples, too.
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
I鈥檓 Jens (long: Jens Oliver Meiert), and I鈥檓 an engineering lead, guerrilla philosopher, and indie publisher. I鈥檝e worked as a technical lead and engineering manager at various companies (e.g., Google); I鈥檓 an active web and tool developer (code optimization, digital defense), a contributor to web standards (like HTML, CSS, WCAG), and a book author (O鈥橰eilly, Frontend Dogma).
I love trying things鈥攊n web development and engineering management, but also in politics and philosophy, where I hold to one idea in particular: that we can only be well if we take good care of everyone. Here on meiert.com I talk about some of my perspectives and experiences. (Please share feedback: Interpret charitably, keep it friendly, but do be critical.)
