AI and HTML: Validating, Omitting Optional Code, and Minifying as Token Optimization
Published on May 12, 2026, filed under development, html, ai. (Share this post, e.g., on Mastodon or on Bluesky.)
Three * arguments (they're straightforward).
- P.1
- Error-free (i.e., valid) HTML is easier to parse.
- P.2
- Data that is easier to parse consumes fewer tokens.
- C
- Therefore, error-free HTML consumes fewer tokens.
- P.1
- HTML that omits non-required, optional HTML code is easier to parse.
- P.2
- Data that is easier to parse consumes fewer tokens.
- C
- Therefore, HTML that omits non-required HTML code consumes fewer tokens.
- P.1
- HTML that is minified is easier to parse.
- P.2
- Data that is easier to parse consumes fewer tokens.
- C
- Therefore, HTML that is minified consumes fewer tokens.
I use “easier to parse” as a shorthand for token efficiency—reducing the character count (input) and the structural ambiguity (output) that leads to token waste.
You can then argue:
If you want your HTML to consume fewer LLM tokens, ensure it’s error-free (validate the output), omit optional code, and minify it.
This is in line with what is commonly known about token optimization: Valid, optimized HTML reduces the number of input tokens as well as secondary token waste (that is, a model needs less context, makes fewer mistakes, and requires less intervention).
The Tools Are All There
Every frontend and web developer worth their salt knows that the tools are all there:
For HTML conformance-checking (validation), the gold standard is the W3C validator (LLMs themselves are terrible at validation). It’s also available on npm, where HTML-validate is an increasingly strong alternative.
For omission of optional HTML code, the opportunities and rules are all clear and documented, and many minifiers—see the next point—come with the option to remove non-required HTML (while keeping the output valid).
For HTML and web page minification as a whole, there are a number of maintained and solid solutions.
My general recommendation? Use the W3C validator, consider HTML-validate in programmatic contexts, and use either HTML Minifier Next for greatest effectiveness, minify-html for best speed, or htmlnano for another great all-around experience (disclosure: I maintain HMN, but base this on available data).
The Bizarre Scenario of AI Accomplishing What Frontend Development Advocacy Never Accomplished
Now, if we end up in a situation in which developers and AI users start to optimize their HTML (for which there are some signs)—notably, using HTML–HTML, omitting optional tags, validating, minifying aggressively—, then AI may have accomplished something I’ve personally largely given up on, which is for our field to embrace HTML as a language and ensure both correctness and a great (for fast) user experience. (Mind you that we’re far from there.)
But: This would not be due to pride in our profession and a sense of honor to ship quality work—but a mundane calculation of how to save money.
As a professional, I’d find this bizarre: We may end up inching closer to said embrace of HTML and quality output—but for reasons that couldn’t be more superficial.
* Why three, wouldn’t one argument suffice? Yes, but that argument would look more complicated (despite just coming with extra conjunctions) and therefore end up less effective.
About Me
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 feedback—interpret charitably, keep it friendly, but do be critical.)
