# postcss-zindex

> Reduce z-index values with PostCSS.

Latest version **9.0.6** (published 2026-10-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-zindex
pnpm add postcss-zindex
yarn add postcss-zindex
bun add postcss-zindex
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 9.0.6 |
| Published | 2026-10-08 |
| First published | 2015-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^22.22.3 \|\| ^24.15.0 \|\| >=26.0 |
| Dependencies | 0 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 4980 |
| Author | Ben Briggs |
| Maintainers | beneb, ludovicofischer, ai, chriseppstein, andyjansson, evilebottnawi, cssnano-bot |
| Keywords | css, normalize, optimise, optimisation, postcss, postcss-plugin, z-index |

## Links

- npm: https://www.npmjs.com/package/postcss-zindex
- Repository: https://github.com/cssnano/cssnano
- Issues: https://github.com/cssnano/cssnano/issues
- npm.io page: https://npm.io/package/postcss-zindex

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 9.0.6 (latest) — 2026-10-08
- 5.0.0-rc.2 (next) — 2021-03-15
- 4.0.0-nightly.2020.2.6 (nightly) — 2021-02-06
- 9.0.5 — 2026-09-29
- 9.0.4 — 2026-09-27
- 9.0.3 — 2026-09-17
- 9.0.2 — 2026-09-05
- 9.0.1 — 2026-09-01
- 9.0.0 — 2026-08-27
- 8.0.4 — 2026-08-16
- 8.0.3 — 2026-08-09
- 8.0.2 — 2026-08-04
- 8.0.1 — 2026-06-11
- 8.0.0 — 2026-05-06
- 7.0.3 — 2026-05-02
- … 43 more at https://npm.io/package/postcss-zindex/versions

## README

# [postcss][postcss]-zindex

> Reduce z-index values with PostCSS.

## Install

With [npm](https://npmjs.org/package/postcss-zindex) do:

```
npm install postcss-zindex --save
```

## Example

Sometimes, you may introduce z-index values into your CSS that are larger than
necessary, in order to improve your understanding of how each stack relates to
the others. For example, you might have a modal overlay at `5000` and the dialog
for it at `5500` - so that modal classes occupy the `5xxx` space.

But in production, it is unnecessary to use such large values for z-index where
smaller values would suffice. This module will reduce all z-index declarations
whilst respecting your original intent; such that the overlay becomes `1` and
the dialog becomes `2`. For more examples, see the [tests](test/index.js).

### Input

```css
.modal {
    z-index: 5000
}

.modal-overlay {
    z-index: 5500
}
```

### Output

```css
.modal {
    z-index: 1
}

.modal-overlay {
    z-index: 2
}
```

Note that this module does not attempt to normalize relative z-index values,
such as `-1`; indeed, it will abort immediately when encountering these values
as it cannot be sure that rebasing mixed positive & negative values will keep
the stacking context intact. Be careful with using this module alongside
JavaScript injected CSS; ideally you should have already extracted all of your
stacking context into CSS.

## API

### zindex([options])

#### options

##### startIndex

Type: `number`
Default: `1`

Set this to any other positive integer if you want to override z-indices from
other sources outside your control. For example if a third party widget has a
maximum z-index of `99`, you can set this to `100` and not have to worry about
stacking conflicts.

## Usage

See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
examples for your environment.

## Contributors

See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/main/CONTRIBUTORS.md).

## License

MIT © [Ben Briggs](https://beneb.info)

[postcss]: https://github.com/postcss/postcss

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