---
title: removeComments
svgo:
  pluginId: removeComments
  defaultPlugin: true
  parameters:
    preservePatterns:
      description: An array of regular expressions ([RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp) or string). If the comment matches any of these, including partial matches, the comment is preserved. Set to `false` to disable this behavior and remove comments indiscriminately.
      default:
        - '^!'
---

Removes XML comments from the document.

XML comments are the content between the `<!--` and `-->` syntax, and do not effect rendering. From an optimization perspective, these can always be safely removed.

By default, this plugin ignores legal comments, also known as "special comments" or "protected comments". These are comments that start with an exclamation point (`!`) and are often used for legal information like copyright notices, licensing, or attribution.

For example, the following comment can be found in [Font Awesome Free](https://fontawesome.com/license/free) icons:

```svg
<!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
```

Removing a comment like this may be considered a breach of the license terms, as Font Awesome Free is released under [CC-BY-4.0 (Creative Commons Attribution)](https://creativecommons.org/licenses/by/4.0/), but removing the comment would strip away that attribution.

## Legal Comments

It's unclear if there are authoritative resources promoting this syntax for legal comments. However, the convention to preserve them based on this can be seen by a number of minification and build tools:

- [clean-css](https://github.com/clean-css/clean-css#how-to-preserve-a-comment-block)
- [CSSO](https://github.com/css/csso#syntaxcompressast-options)
- [esbuild](https://esbuild.github.io/api/#legal-comments)
- [Sass](https://sass-lang.com/documentation/syntax/comments/)
- [Terser](https://github.com/terser/terser#keeping-copyright-notices-or-other-comments) / [terser-webpack-plugin](https://github.com/webpack-contrib/terser-webpack-plugin#preserve-comments)
- [UglifyJS](https://github.com/mishoo/UglifyJS#keeping-copyright-notices-or-other-comments)
- [YUI Compressor](https://github.com/yui/yuicompressor#notes)
