# postcss-reduce-idents

> Reduce custom identifiers with PostCSS.

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

## Install

```sh
npm install postcss-reduce-idents
pnpm add postcss-reduce-idents
yarn add postcss-reduce-idents
bun add postcss-reduce-idents
```

## 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.7 |
| Published | 2026-10-10 |
| First published | 2015-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^22.22.3 \|\| ^24.15.0 \|\| >=26.0 |
| Dependencies | 1 |
| Unpacked size | 54 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Author | Ben Briggs |
| Maintainers | beneb, trysound, ludovicofischer, ai, chriseppstein, andyjansson, evilebottnawi, cssnano-bot |
| Keywords | css, postcss, postcss-plugin |

## Links

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

## Dependencies (1)

- [cssnano-utils](https://npm.io/package/cssnano-utils.md) ^9.0.0

## 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.7 (latest) — 2026-10-10
- 5.0.0-rc.2 (next) — 2021-03-15
- 4.0.0-nightly.2020.2.6 (nightly) — 2021-02-06
- 9.0.6 — 2026-10-08
- 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
- … 50 more at https://npm.io/package/postcss-reduce-idents/versions

## README

# [postcss][postcss]-reduce-idents

> Reduce [custom identifiers][idents] with PostCSS.


## Install

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

```
npm install postcss-reduce-idents --save
```


## Example

### Input

This module will rename custom identifiers in your CSS files; it does so by
converting each name to a index, which is then encoded into a legal identifier.
A legal custom identifier in CSS is case sensitive and must start with a
letter, but can contain digits, hyphens and underscores. There are over 3,000
possible two character identifiers, and 51 possible single character identifiers
that will be generated.

```css
@keyframes whiteToBlack {
    0% {
        color: #fff
    }
    to {
        color: #000
    }
}

.one {
    animation-name: whiteToBlack
}
```

### Output

```css
@keyframes a {
    0% {
        color: #fff
    }
    to {
        color: #000
    }
}

.one {
    animation-name: a
}
```

Note that this module does not handle identifiers that are not linked together.
The following example will not be transformed in any way:

```css
@keyframes fadeOut {
    0% { opacity: 1 }
    to { opacity: 0 }
}

.fadeIn {
    animation-name: fadeIn;
}
```

A name that reads as a keyword of the property it is written in is also left
alone, because renaming it would change what the declaration means. In
`animation: linear 2s linear`, whether a `linear` is the easing function or the
name of the animation depends on the order the value is matched in, so neither
is touched.

It works for `@keyframes`, `@counter-style`, custom `counter` values and grid area definitions. See the
[documentation][idents] for more information, or the [tests](test) for more
examples.


## Usage

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


## API

### reduceIdents([options])

#### options

##### counter

Type: `boolean`  
Default: `true`

Pass `false` to disable reducing `content`, `counter-reset` and `counter-increment` declarations.

##### keyframes

Type: `boolean`  
Default: `true`

Pass `false` to disable reducing `keyframes` rules and `animation` declarations.

##### counterStyle

Type: `boolean`  
Default: `true`

Pass `false` to disable reducing `counter-style` rules and `list-style` and `system` declarations.

##### gridTemplate

Type: `boolean`  
Default: `true`

Pass `false` to disable reducing `grid-template`, `grid-area`, `grid-column`, `grid-row` and `grid-template-areas` declarations.

##### encoder

Type: `function`  
Default: [`lib/encode.js`](https://github.com/cssnano/postcss-reduce-idents/blob/master/src/lib/encode.js)

Pass a custom function to encode the identifier with (e.g.: as a way of prefixing them automatically).

It receives two parameters:
  - A `String` with the node value.
  - A `Number` identifying the index of the occurrence.

## Contributors

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


## License

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

[idents]:  https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident

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

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