# postcss-autoreset

> PostCSS plugin for partial styles reset

Latest version **3.1.0** (published 2024-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-autoreset
pnpm add postcss-autoreset
yarn add postcss-autoreset
bun add postcss-autoreset
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2024-02-19 |
| First published | 2015-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 246 |
| Author | Maksim Koretskiy |
| Maintainers | maximkoretskiy |
| Keywords | postcss, postcss-plugin, css, reset, autoreset, isolation |

## Links

- npm: https://www.npmjs.com/package/postcss-autoreset
- Repository: https://github.com/maximkoretskiy/postcss-autoreset
- Homepage: https://github.com/maximkoretskiy/postcss-reset
- Issues: https://github.com/maximkoretskiy/postcss-reset/issues
- npm.io page: https://npm.io/package/postcss-autoreset

## Dependencies (1)

- [postcss-js](https://npm.io/package/postcss-js.md) ^4.0.1

## 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

- 3.1.0 (latest) — 2024-02-19
- 3.0.4 — 2021-05-21
- 3.0.3 — 2020-10-15
- 3.0.2 — 2020-10-15
- 3.0.1 — 2020-10-09
- 3.0.0 — 2020-10-01
- 2.0.2 — 2018-02-21
- 2.0.1 — 2017-08-25
- 2.0.0 — 2017-05-30
- 1.2.1 — 2016-10-09
- 1.2.0 — 2016-09-29
- 1.1.5 — 2016-01-21
- 1.1.4 — 2016-01-21
- 1.1.3 — 2016-01-20
- 1.1.2 — 2016-01-10
- … 4 more at https://npm.io/package/postcss-autoreset/versions

## README

# PostCSS Auto Reset

[![Build Status][ci-img]][ci] [![NPM][npm-img]][npm] [![David DM][david-img]][david]

<img align="right" width="135" height="95"
     title="Philosopher’s stone, logo of PostCSS"
     src="http://postcss.github.io/postcss/logo-leftp.png">

[PostCSS] plugin for automatic conditional rules reset. Useful for creation of
bullet-proof styles isolation in your extension. Can be used in combination with
[postcss-initial][initial].

[postcss]: https://github.com/postcss/postcss
[ci-img]: https://travis-ci.org/maximkoretskiy/postcss-autoreset.svg
[ci]: https://travis-ci.org/maximkoretskiy/postcss-autoreset
[npm-img]: https://badge.fury.io/js/postcss-autoreset.svg
[npm]: https://www.npmjs.com/package/postcss-autoreset
[david-img]: https://david-dm.org/maximkoretskiy/postcss-autoreset.svg
[david]: https://david-dm.org/maximkoretskiy/postcss-autoreset
[initial]: https://github.com/maximkoretskiy/postcss-initial

The following CSS is written in [BEM](https://en.bem.info/) notation.

```css
.block {
  padding: 1em;
}

.block:hover {
  background-color: red;
}

.block__element {
  margin: 1em;
}

.block--modifier {
  border: 1em;
}
```

```css
.block,
.block__element {
  /* combined reset block */
  all: initial;
}

.block {
  /* reseted */
  padding: 1em;
}

.block:hover {
  /* ignored, we don`t need to reset pseudoclasses  */
  background-color: red;
}

.block__element {
  /* reseted */
  margin: 1em;
}

.block--modifier {
  /* ignored, we don`t need to reset BEM modifiers  */
  border: 1em;
}
```

## Options

### reset

Set of properties that we use to reset rules.  
Takes `string` or `object`.  
Possible values:

- 'initial' - `all: initial`;
- 'sizes' - reset size properties.

Use object to create your own reset. CSS-in-JS notation is supported.

**Example**

```js
postcss([
  require("postcss-autoreset")({
    reset: {
      margin: 0,
      padding: 0,
      borderRadius: 0,
    },
  }),
]);
```

### rulesMatcher

Rules filter function.  
Takes `string` or `function`.  
Possible values:

- 'bem' - reset all [BEM](https://en.bem.info/) blocks and element, ignore modifiers and pseudoclasses. (naming: `.block__element-modifier`);
- 'suit' - reset all [SUIT CSS](https://suitcss.github.io/) components and parts, ignore modifiers, states and pseudoclasses.

You can define custom rules filter to fit your styles naming.

**Example**

```js
postcss([
  require("postcss-autoreset")({
    rulesMatcher: (rule) => rule.selector.match(/regexp/),
  }),
]);
```

Reset only simple rules. See [#28](https://github.com/maximkoretskiy/postcss-autoreset/issues/28)

```js
postcss([
  require("postcss-autoreset")({
    rulesMatcher: (rule) => rule.selector.match(/^[.]\w+$/),
  }),
]);
```

## Usage

**Step 1:** Install plugin:

```sh
npm install --save-dev postcss postcss-autoreset
```

**Step 2:** Check you project for existed PostCSS config: `postcss.config.js`
in the project root, `"postcss"` section in `package.json`
or `postcss` in bundle config.

If you do not use PostCSS, add it according to [official docs]
and set this plugin in settings.

**Step 3:** Add the plugin to plugins list:

```diff
module.exports = {
  plugins: [
+   require('postcss-autoreset')(),
    require('autoprefixer')
  ]
}
```

[official docs]: https://github.com/postcss/postcss#usage

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