Jens Oliver Meiert

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

HTML Minifier Next: Exempt CSS, JS, and SVG From Minification, Collapse No-Break Spaces and Empty Attributes, Higher Correctness

Published on Oct 6, 2026, filed under , , , , . (Share this post, e.g., on Mastodon.)

HTML Minifier Next (HMN)—minifier user? check the benchmarks!—received more updates over the last couple of weeks. As in the past, the highlights:

CSS, JS, and SVG Minification Exceptions

If you want to exempt CSS, JavaScript, or SVG snippets from minification, you can now do so via the canMinify API options. For example, to keep certain CSS as is, use canMinifyCSS as such:

const result = await minify(html, {
  minifyCSS: true,
  canMinifyCSS: text => !text.includes('/* keep */')
});

Thanks Paul P. for the suggestion, the proactive PR, and teaming up on getting this out!

Remove Whitespace Next to No-Break Spaces

collapseNoBreakSpaces is a new option to trim whitespace next to no-break spaces, narrow no-break spaces, and figure spaces in text (e.g., a   b → a b). This is useful for markup from editors and CMSs that pad   with regular spaces: Not only do these spaces add bytes, they also allow a line break right next to the no-break space, defeating its purpose. As removing them can slightly narrow the gap that’s rendered, the option is off by default.

Thanks Andreas Borutta for the suggestion!

Collapse Empty Attributes

collapseEmptyAttributes adds a long-missing HTML Minifier feature to allow for constructs like alt="" (assuming that in such a case, the image is decorative) to be collapsed to alt (which is valid).

collapseEmptyAttributes is enabled in the “comprehensive” preset.

Ensure High(er) Correctness

HTML is not trivial, and optimizing HTML is not trivial, either. HMN has taught me that with all the various inaccuracies (bugs) that I fixed over time, whether inherited or self-inflicted.

Many of the recent fixes bring HMN closer to how browsers parse HTML: when a p element is closed (and when it isn’t—in quirks mode, table doesn’t close a p), how slashes on start tags are read (<div/> doesn’t close anything), how the content of elements like textarea and title is handled, how script and style elements and CDATA sections in SVG and MathML are read, and how element and attribute names not written in lowercase are recognized. Other fixes make sure collapseWhitespace and collapseInlineTagWhitespace don’t run words together anymore, for example around data, code, or script elements.

Part of this is keeping up with HTML itself: This summer, the HTML standard started parsing processing instructions like <?marker name="…">, which <template for> uses to mark where streamed content goes (until then, HTML parsers had read them as bogus comments). HMN stopped at these with a parse error; it now reads them and keeps them as written. Its default ignoreCustomFragments pattern for <? … ?> code also got narrower, as it could reach from a processing instruction to the next ?>, and break the markup in between.

To see what HMN has to work around in your markup, continueOnParseError now also reports each parse error it handles, with line and column (in the CLI via --verbose or --dry):

Warning: Parse error at line 1487, column 21: Dropped end tag without a name

Enjoy Higher Efficiency and Effectiveness

Multi-file runs now spread across worker threads (--workers), which HMN uses automatically when a run carries enough input, handing out the largest files first. Together with optimizations in the parser, attribute handling, the whitespace pass, and entity decoding, HMN got faster yet again—Minifier Benchmarks has the data.

On top of this, removeUnusedCSS now also removes individual unused selectors (.used, .unused {…} → .used {…}) as well as selectors for elements a document doesn’t contain, minifyURLs covers more attributes (like <iframe src> and <video poster>), and repeated class names get removed (class="a b a" → class="a b"). The changelog has more details.


This is it for some of the last changes. As usual, if you run into an issue or have a suggestion, please file an issue. And if you or your organization get value out of this work on HTML Minifier Next, please support the project. Thank you!

About Me

Portrait sketch of Jens Oliver Meiert.

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 (e.g., Google); I’m an active web and tool developer (code optimization, digital defense), a contributor to web standards (like HTML, CSS, WCAG), and a book author (O’Reilly, Frontend Dogma).

I love trying things—in 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. (Interpret charitably but be critical—and share feedback and advice that makes my work better.)