# htmlnano

> Modular HTML minifier, built on top of the PostHTML

Latest version **3.5.1** (published 2026-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install htmlnano
pnpm add htmlnano
yarn add htmlnano
bun add htmlnano
```

Provides the command `htmlnano`.

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.5.1 |
| Published | 2026-09-12 |
| First published | 2016-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 414.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 296 |
| Author | Kirill Maltsev |
| Maintainers | scrum, maltsev |
| Keywords | posthtml, posthtml-plugin, html, postproccessor, minifier |

## Links

- npm: https://www.npmjs.com/package/htmlnano
- Repository: https://github.com/maltsev/htmlnano
- Issues: https://github.com/maltsev/htmlnano/issues
- npm.io page: https://npm.io/package/htmlnano

## Dependencies (6)

- [entities](https://npm.io/package/entities.md) ^8.0.0
- [posthtml](https://npm.io/package/posthtml.md) ^0.16.5
- [commander](https://npm.io/package/commander.md) ^15.0.0
- [tinyglobby](https://npm.io/package/tinyglobby.md) ^0.2.17
- [cosmiconfig](https://npm.io/package/cosmiconfig.md) ^10.0.0
- [@types/relateurl](https://npm.io/package/@types/relateurl.md) ^0.2.33

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 3.5.1 (latest) — 2026-09-12
- 3.5.0 — 2026-09-08
- 3.4.1 — 2026-08-31
- 3.4.0 — 2026-07-12
- 3.3.2 — 2026-05-21
- 3.3.1 — 2026-05-17
- 3.3.0 — 2026-05-16
- 3.2.1 — 2026-04-20
- 3.2.0 — 2026-03-01
- 3.1.0 — 2026-02-03
- 3.0.0 — 2025-12-22
- 2.1.5 — 2025-09-19
- 2.1.4 — 2025-09-05
- 2.1.3 — 2025-09-03
- 2.1.2 — 2025-04-30
- … 32 more at https://npm.io/package/htmlnano/versions

## README

<h1><img src="docs/static/logo.png" alt="htmlnano logo" width="90" align="absmiddle">&nbsp;htmlnano</h1>

[![npm version](https://badge.fury.io/js/htmlnano.svg)](http://badge.fury.io/js/htmlnano)
![CI](https://github.com/maltsev/htmlnano/actions/workflows/ci.yml/badge.svg)

Modular HTML minifier, built on top of the [PostHTML](https://github.com/posthtml/posthtml). Inspired by [cssnano](https://github.com/cssnano/cssnano).

## Documentation
https://htmlnano.netlify.app


## Usage

```bash
npm install htmlnano
```

```js
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:

```bash
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

[html-minifier-terser]: https://www.npmjs.com/package/html-minifier-terser/v/7.2.0
[html-minifier-next]: https://www.npmjs.com/package/html-minifier-next/v/5.0.3
[htmlnano]: https://www.npmjs.com/package/htmlnano/v/3.1.0
[minify]: https://www.npmjs.com/package/@tdewolff/minify/v/2.24.8
[minify-html]: https://www.npmjs.com/package/@minify-html/node/v/0.18.1

| Website                                                         | Source (KB) | [html-minifier-terser] | [html-minifier-next] | [htmlnano] |  [minify] | [minify-html] |
| --------------------------------------------------------------- | ----------: | ---------------------: | -------------------: | ---------: | --------: | ------------: |
| [alistapart.com](https://alistapart.com/)                       |          63 |                   7.6% |                11.6% |      34.6% |     11.1% |          8.6% |
| [developer.mozilla.org](https://developer.mozilla.org/en-US/)   |         109 |                  38.0% |                41.7% |      52.8% |     40.1% |         39.9% |
| [css-tricks.com](https://css-tricks.com)                        |          11 |                   8.2% |                34.1% |      37.2% |     18.8% |          8.5% |
| [en.wikipedia.org](https://en.wikipedia.org/wiki/Main_Page)     |         224 |                   4.5% |                 7.4% |       7.2% |     60.6% |          2.9% |
| [github.com](https://github.com/)                               |         546 |                   3.0% |                 9.7% |      16.7% |      7.3% |          5.7% |
| [edri.org](https://edri.org)                                    |          80 |                   7.7% |                12.3% |      30.6% |     12.3% |          8.2% |
| [leanpub.com](https://leanpub.com)                              |         251 |                   1.3% |                 6.9% |       6.3% |      6.0% |          1.7% |
| [stackoverflow.blog](https://stackoverflow.blog/)               |         139 |                   3.9% |                 5.7% |       7.0% |      4.6% |          4.7% |
| [html.spec.whatwg.org](https://html.spec.whatwg.org/multipage/) |         149 |                  -3.9% |                 0.7% |      -2.6% |      0.3% |          0.2% |
| [eff.org](https://eff.org)                                      |          54 |                   8.8% |                14.7% |      10.9% |     13.4% |          9.7% |
| [apple.com](https://apple.com/)                                 |         229 |                   8.9% |                12.5% |      11.5% |     10.4% |          9.5% |
| [w3.org](https://w3.org/)                                       |          50 |                  19.0% |                24.6% |      23.4% |     24.4% |         20.3% |
| [mastodon.social](https://mastodon.social/explore)              |          37 |                   3.4% |                 6.8% |      14.6% |      5.9% |          3.6% |
| [bbc.co.uk](https://bbc.co.uk)                                  |         694 |                   0.8% |                 6.3% |       5.9% |      4.7% |          1.2% |
| [un.org](https://un.org/en/)                                    |         151 |                  14.2% |                22.5% |      41.2% |     20.0% |         15.0% |
| [lafrenchtech.gouv.fr](https://lafrenchtech.gouv.fr/)           |         152 |                  13.2% |                17.9% |      64.1% |     17.0% |         13.8% |
| [sitepoint.com](https://sitepoint.com)                          |         497 |                   0.8% |                 7.4% |      12.9% |      6.1% |          0.9% |
| [faz.net](https://faz.net/aktuell/)                             |        1572 |                   3.4% |                 8.0% |      15.8% |      4.8% |          3.6% |
| [weather.com](https://weather.com)                              |        2395 |                   0.3% |                11.4% |      18.1% |     11.0% |          0.6% |
| [tc39.es](https://tc39.es/ecma262/)                             |        7254 |                   8.5% |                11.3% |       9.3% |      9.5% |          9.1% |
| [home.cern](https://home.cern)                                  |         151 |                  37.1% |                46.4% |      40.2% |     38.9% |         39.5% |
| **Avg. minify rate**                                            |             |               **9.0%** |            **15.2%** |  **21.8%** | **15.6%** |      **9.9%** |

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

---
_Source: https://npm.io/package/htmlnano · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
