
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
strip-css-comments
Advanced tools
Strip comments from CSS
Also available as a Gulp/Grunt/Broccoli plugin.
$ npm install strip-css-comments
import stripCssComments from 'strip-css-comments';
// By default important comments `/*!` are preserved
stripCssComments('/*! <copyright> */ body { /* unicorns */color: hotpink; }');
//=> '/*! <copyright> */ body { color: hotpink; }'
// `preserve: false` will strip all comments including `/*!`
stripCssComments(
'/*! <copyright> */ body { /* unicorns */color: hotpink; }',
{preserve: false}
);
//=> 'body { color: hotpink; }'
// Preserve comments based on a regex
stripCssComments(
'/*# preserved */ body { /* unicorns */color: hotpink; }',
{preserve: /^#/}
);
//=> '/*# preserved */ body { color: hotpink; }'
// Preserve comments based on the return value of the supplied function
stripCssComments(
'/*# preserved */ body { /* unicorns */color: hotpink; }',
{
preserve: comment => comment.charAt(0) === '#'
}
);
//=> '/*# preserved */ body { color: hotpink; }'
Type: string
String with CSS.
Type: object
Type: boolean | RegExp | Function
Default: true
true - Preserve important comments /*! */.false - Strip all comments.RegExp - Preserve comments where the comment body matches a regular expression.Function - Preserve comments for which a function returns true. The function is called on each comment, gets the comment body as the first argument, and is expected to return a boolean of whether to preserve the comment.Type: boolean
Default: true
Replace comments with whitespace instead of stripping them entirely.
$ npm run bench
FAQs
Strip comments from CSS
The npm package strip-css-comments receives a total of 58,589 weekly downloads. As such, strip-css-comments popularity was classified as popular.
We found that strip-css-comments demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.