# postcss-discard-comments

> Discard comments in your CSS files with PostCSS.

Latest version **9.0.3** (published 2026-09-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-discard-comments
pnpm add postcss-discard-comments
yarn add postcss-discard-comments
bun add postcss-discard-comments
```

## 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.3 |
| Published | 2026-09-17 |
| First published | 2015-03-18 |
| 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 | 18.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4976 |
| Author | Ben Briggs |
| Maintainers | beneb, trysound, ludovicofischer, ai, chriseppstein, andyjansson, evilebottnawi, cssnano-bot |
| Keywords | css, comments, postcss, postcss-plugin |

## Links

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

## Dependencies (1)

- [postcss-selector-parser](https://npm.io/package/postcss-selector-parser.md) ^7.1.6

## 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.3 (latest) — 2026-09-17
- 5.0.0-rc.2 (next) — 2021-03-15
- 4.0.0-nightly.2020.2.6 (nightly) — 2021-02-06
- 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.8 — 2026-05-02
- 7.0.7 — 2026-04-20
- 7.0.6 — 2026-03-06
- 7.0.5 — 2025-10-29
- … 53 more at https://npm.io/package/postcss-discard-comments/versions

## README

# [postcss][postcss]-discard-comments

> Discard comments in your CSS files with PostCSS.


## Install

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

```
npm install postcss-discard-comments --save
```


## Example

### Input

```css
h1/* heading */{
    margin: 0 auto
}
```

### Output

```css
h1 {
    margin: 0 auto
}
```

This module discards comments from your CSS files; by default, it will remove
all regular comments (`/* comment */`) and preserve comments marked as important
(`/*! important */`).

Note that this module does not handle source map comments because they are not
available to it; PostCSS handles this internally, so if they are removed then
you will have to [configure source maps in PostCSS][maps].

[maps]: https://github.com/postcss/postcss/blob/master/docs/source-maps.md


## API

### comments([options])

#### options

##### remove(function)

Type: `function`
Return: `boolean`
Variable: `comment` contains a comment without `/**/`

For each comment, return true to remove, or false to keep the comment.

```js
function(comment) {}
```

```js
var css = '/* headings *//*@ h1 */h1{margin:0 auto}/*@ h2 */h2{color:red}';
console.log(postcss(comments({
    remove: function(comment) { return comment[0] == "@"; }
})).process(css).css);
//=> /* headings */h1{margin:0 auto}h2{color:red}
```
**NOTE:** If you use the `remove` function other options will not be available.

##### removeAll

Type: `boolean`
Default: `false`

Remove all comments marked as important.

```js
var css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}';
console.log(postcss(comments({removeAll: true})).process(css).css);
//=> h1{margin:0 auto}h2{color:red}
```

##### removeAllButFirst

Type: `boolean`
Default: `false`

Remove all comments marked as important, but the first one.

```js
var css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}';
console.log(postcss(comments({removeAllButFirst: true})).process(css).css);
//=> /*! heading */h1{margin:0 auto}h2{color:red}
```


## 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-discard-comments · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
