npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

Iโ€™ve always been into building performant and accessible sites, but lately Iโ€™ve been taking it extremely seriously. So much so that Iโ€™ve been building a tool to help me optimize and monitor the sites that I build to make sure that Iโ€™m making an attempt to offer the best experience to those who visit them. If youโ€™re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, ๐Ÿ‘‹, Iโ€™m Ryan Hefnerย  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If youโ€™re interested in other things Iโ€™m working on, follow me on Twitter or check out the open source projects Iโ€™ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soonโ€“ish.

Open Software & Tools

This site wouldnโ€™t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you ๐Ÿ™

ยฉ 2025 โ€“ย Pkg Stats / Ryan Hefner

postcss-remove-duplicate-values

v2.0.0

Published

๐Ÿš€ PostCSS plugin that intelligently removes duplicate CSS properties, reduces bundle size, and improves CSS maintainability. Handles !important declarations, vendor prefixes, and selector filtering with zero configuration.

Downloads

634

Readme

postcss-remove-duplicate-values

Smart PostCSS plugin that removes duplicate CSS properties, reduces bundle size, and improves CSS maintainability.

โœจ What It Does?

Automatically removes duplicate CSS properties from your stylesheets while keeping the most important ones. Perfect for cleaning up CSS and improving performance.

๐ŸŽฏ Key Features

  • ๐Ÿงน Removes duplicate properties (keeps the last one)
  • โšก Handles !important declarations intelligently
  • ๐ŸŽจ Supports vendor prefixes and modern CSS
  • ๐ŸŽฏ Filters specific selectors (optional)
  • ๐Ÿ—‘๏ธ Cleans empty rules (configurable)
  • ๐Ÿš€ Zero configuration needed

๐Ÿš€ Quick Start

1. Install

npm install postcss-remove-duplicate-values --save-dev
# or
pnpm add postcss-remove-duplicate-values -D
# or
yarn add postcss-remove-duplicate-values -D

2. Use in PostCSS

// postcss.config.js
module.exports = {
  plugins: [
    require('postcss-remove-duplicate-values')
  ]
}

3. That's it! ๐ŸŽ‰

The plugin automatically removes duplicates from your CSS.

๐Ÿ“– Examples

Basic Duplicate Removal

/* Before */
.button {
  color: red;
  color: blue;
  margin: 10px;
  margin: 20px;
}

/* After */
.button {
  color: blue;
  margin: 20px;
}

!important Handling

/* Before */
.button {
  color: red !important;
  color: blue;
  font-weight: normal;
  font-weight: bold !important;
}

/* After */
.button {
  color: red !important;
  font-weight: bold !important;
}

Vendor Prefixes

/* Before */
.button {
  transform: translateX(40px);
  -webkit-transform: translateX(10px);
  -moz-transform: translateX(10px);
  transform: translateX(10px);
}

/* After */
.button {
  /* Plugin removes duplicate 'transform' properties, keeping the last one */
  /* Vendor prefixes are preserved */
  -webkit-transform: translateX(10px);
  -moz-transform: translateX(10px);
  transform: translateX(10px);
}

โš™๏ธ Configuration Options

Before applying the plugin, you can configure the following options:

| Option | Type | Default | | --------------------------------- | --------------------------------------------------- | ----------- | | selector | (selector: string) => boolean \| string \| RegExp | undefined | | preserveEmpty | boolean | false |

selector

Filter which CSS selectors to process.

// Only process .button selectors
removeDuplicateValues({
  selector: '.button'
})

// Process selectors matching regex
removeDuplicateValues({
  selector: /^\.btn-/
})

// Custom function
removeDuplicateValues({
  selector: (selector) => selector.includes('button')
})

preserveEmpty

Keep or remove empty CSS rules.

// Remove empty rules (default)
removeDuplicateValues({
  preserveEmpty: false
})

// Keep empty rules
removeDuplicateValues({
  preserveEmpty: true
})

๐Ÿ”ง Advanced Usage

With PostCSS API

const postcss = require('postcss')
const removeDuplicateValues = require('postcss-remove-duplicate-values')

const css = `
.button {
  color: red;
  color: blue;
}`

postcss([removeDuplicateValues()])
  .process(css)
  .then(result => {
    console.log(result.css)
    // Output: .button { color: blue; }
  })

With Build Tools

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              plugins: [
                require('postcss-remove-duplicate-values')
              ]
            }
          }
        ]
      }
    ]
  }
}

๐Ÿ“š More Examples

Selector Filtering

/* Input CSS */
.container {
  color: red;
  color: blue;
}
.button {
  margin: 10px;
  margin: 20px;
}

/* With selector: '.container' */
.container {
  color: blue;
}
.button {
  margin: 10px;
  margin: 20px; /* Not processed */
}

Empty Rule Handling

/* Input CSS */
.empty-rule {
}
.button {
  color: blue;
}

/* With preserveEmpty: false */
.button {
  color: blue;
}
/* .empty-rule removed */

/* With preserveEmpty: true */
.empty-rule {
}
.button {
  color: blue;
}

๐ŸŽฎ Try It Live!

Test the plugin in real-time with our interactive playground:

๐ŸŽฎ Try the Playground โ†’

What You Can Do in the Playground:

  • โœจ Test CSS processing in real-time
  • ๐ŸŽฏ Experiment with options (selector filtering, empty rule preservation)
  • ๐Ÿ“š Try pre-built examples for common scenarios
  • ๐Ÿ“Š See live statistics of duplicate removal results
  • ๐ŸŽจ Understand plugin behavior through interactive examples

Made with โค๏ธ by Bharat Rawat