htmlnano
Modular HTML minifier, built on top of the PostHTML
Last updated 2 months ago by maltsev .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install htmlnano 
SYNC missed versions from official npm registry.

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

# 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-10-11

Website Source (KB) html-minifier-terser html-minifier-next htmlnano minify minify-html swc-html
developer.mozilla.org 119 39.1% 41.9% N/A 41.2% 41.1% 41.6%
alistapart.com 64 6.8% 11.0% 35.6% 10.3% 8.0% 11.0%
css-tricks.com 150 N/A 14.1% 25.2% 12.6% 9.1% 13.3%
en.wikipedia.org 247 4.7% 7.7% 9.8% 6.0% 6.1% 6.3%
html.spec.whatwg.org 151 -3.9% 0.3% 0.2% 0.3% 0.2% 1.5%
edri.org 84 7.4% 13.0% 32.1% 12.1% 7.9% 12.6%
home.cern 292 N/A 11.7% 24.5% 8.0% 4.7% 10.2%
mastodon.social 50 3.8% 13.3% 13.3% 5.7% 7.0% 8.3%
leanpub.com 524 1.2% 8.9% 9.5% 5.3% 1.7% 5.8%
stackoverflow.blog 134 4.0% 7.0% 7.1% 4.6% 4.9% 5.5%
weather.com 360 0.5% 8.3% 8.6% 6.4% 0.9% 6.4%
eff.org 54 8.6% 15.6% 14.9% 13.1% 11.1% 13.1%
apple.com 248 6.1% 8.6% 9.1% 7.6% 6.7% 7.0%
w3.org 50 17.9% 23.3% 23.0% 22.9% 19.0% 22.9%
bbc.co.uk 752 0.8% 7.1% 7.3% 4.8% 1.2% 6.3%
un.org 161 13.5% 22.4% 42.2% 19.1% 14.3% 16.7%
github.com 564 1.5% 15.2% N/A 5.2% 4.1% 4.6%
faz.net 1366 3.9% 10.6% 16.6% 4.3% 4.3% 9.4%
tc39.es 7450 5.7% 8.1% 7.5% 6.6% 6.2% 7.9%
lafrenchtech.gouv.fr 184 26.4% 30.6% 68.3% 29.8% 26.9% 30.5%
Avg. minify rate 6.7% 12.2% 19.1% 9.9% 7.9% 10.7%

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

Current Tags

  • 3.6.1                                ...           latest (2 months ago)

49 Versions

  • 3.6.1                                ...           2 months ago
  • 3.6.0                                ...           2 months ago
  • 3.5.1                                ...           2 months ago
  • 3.5.0                                ...           3 months ago
  • 3.4.1                                ...           3 months ago
  • 3.4.0                                ...           4 months ago
  • 3.3.2                                ...           6 months ago
  • 3.3.1                                ...           6 months ago
  • 3.3.0                                ...           6 months ago
  • 3.2.1                                ...           7 months ago
  • 3.2.0                                ...           9 months ago
  • 3.1.0                                ...           10 months ago
  • 3.0.0                                ...           a year ago
  • 2.1.5                                ...           a year ago
  • 2.1.4                                ...           a year ago
  • 2.1.3                                ...           a year ago
  • 2.1.2                                ...           2 years ago
  • 2.1.1                                ...           3 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.4                                ...           4 years ago
  • 2.0.3                                ...           4 years ago
  • 2.0.2                                ...           5 years ago
  • 2.0.1 [deprecated]           ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0 [deprecated]           ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           6 years ago
  • 0.2.9                                ...           6 years ago
  • 0.2.8                                ...           6 years ago
  • 0.2.7                                ...           6 years ago
  • 0.2.6                                ...           6 years ago
  • 0.2.5                                ...           7 years ago
  • 0.2.4                                ...           7 years ago
  • 0.2.3                                ...           8 years ago
  • 0.2.2                                ...           8 years ago
  • 0.2.1                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.10                                ...           8 years ago
  • 0.1.9                                ...           9 years ago
  • 0.1.8                                ...           9 years ago
  • 0.1.7                                ...           9 years ago
  • 0.1.6                                ...           9 years ago
  • 0.1.5                                ...           11 years ago
  • 0.1.4                                ...           11 years ago
  • 0.1.3                                ...           11 years ago
  • 0.1.2                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
Maintainers (2)
Downloads
Total 98
Today 3
This Week 10
This Month 75
Last Day 0
Last Week 4
Last Month 0
Dependencies (6)
Dev Dependencies (35)

© 2010 - cnpmjs.org x YWFE | Home | YWFE