htmlnano

Modular HTML minifier, built on top of the PostHTML. Inspired by cssnano.
Documentation
https://htmlnano.netlify.app
Usage
const htmlnano = require('htmlnano');
const options = {
removeEmptyAttributes: false, // Disable the module "removeEmptyAttributes"
collapseWhitespace: 'conservative' // Pass options to the module "collapseWhitespace"
};
// posthtml, posthtml-render, and posthtml-parse options
const postHtmlOptions = {
sync: true, // https://github.com/posthtml/posthtml#usage
lowerCaseTags: true, // https://github.com/posthtml/posthtml-parser#options
quoteAllAttributes: false, // https://github.com/posthtml/posthtml-render#options
};
htmlnano
// "preset" arg might be skipped (see "Presets" section below for more info)
// "postHtmlOptions" arg might be skipped
.process(html, options, preset, postHtmlOptions)
Also, you can use it as CLI tool:
node_modules/.bin/htmlnano --help
# STDIN -> STDOUT
cat test.html | node_modules/.bin/htmlnano > test.min.html
# Single file
node_modules/.bin/htmlnano test.html -o test.min.html
# Multiple files / globs (quote globs so htmlnano expands them itself)
node_modules/.bin/htmlnano "dist/**/*.html" --output-dir minified
node_modules/.bin/htmlnano "dist/**/*.html" --in-place
More usage examples (PostHTML, CLI, Webpack): https://htmlnano.netlify.app/usage
Benchmarks
Updated: 2026-11-13
Latest benchmarks: https://github.com/maltsev/html-minifiers-benchmark (updated daily).