镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
maltsevPublic

About

Modular HTML minifier, built on top of the PostHTML

Resources

Stars

296 stars

Watchers

2 watching

Forks

Repository files navigation

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).

About

Modular HTML minifier, built on top of the PostHTML

Resources

Stars

296 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages