README.md

February 28, 2026 · View on GitHub

htmlnano logo htmlnano

npm version CI

Modular HTML minifier, built on top of the PostHTML. Inspired by cssnano.

Documentation

https://htmlnano.netlify.app

Usage

npm install htmlnano
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)
    .then(function (result) {
        // result.html is minified
    })
    .catch(function (err) {
        console.error(err);
    });

Also, you can use it as CLI tool:

node_modules/.bin/htmlnano --help

More usage examples (PostHTML, CLI, Webpack): https://htmlnano.netlify.app/usage

Benchmarks

WebsiteSource (KB)html-minifier-terserhtml-minifier-nexthtmlnanominifyminify-html
alistapart.com637.6%11.6%34.6%11.1%8.6%
developer.mozilla.org10938.0%41.7%52.8%40.1%39.9%
css-tricks.com118.2%34.1%37.2%18.8%8.5%
en.wikipedia.org2244.5%7.4%7.2%60.6%2.9%
github.com5463.0%9.7%16.7%7.3%5.7%
edri.org807.7%12.3%30.6%12.3%8.2%
leanpub.com2511.3%6.9%6.3%6.0%1.7%
stackoverflow.blog1393.9%5.7%7.0%4.6%4.7%
html.spec.whatwg.org149-3.9%0.7%-2.6%0.3%0.2%
eff.org548.8%14.7%10.9%13.4%9.7%
apple.com2298.9%12.5%11.5%10.4%9.5%
w3.org5019.0%24.6%23.4%24.4%20.3%
mastodon.social373.4%6.8%14.6%5.9%3.6%
bbc.co.uk6940.8%6.3%5.9%4.7%1.2%
un.org15114.2%22.5%41.2%20.0%15.0%
lafrenchtech.gouv.fr15213.2%17.9%64.1%17.0%13.8%
sitepoint.com4970.8%7.4%12.9%6.1%0.9%
faz.net15723.4%8.0%15.8%4.8%3.6%
weather.com23950.3%11.4%18.1%11.0%0.6%
tc39.es72548.5%11.3%9.3%9.5%9.1%
home.cern15137.1%46.4%40.2%38.9%39.5%
Avg. minify rate9.0%15.2%21.8%15.6%9.9%

Latest benchmarks: https://github.com/maltsev/html-minifiers-benchmark (updated daily).