stylehacks (5.1.1)

Published 2026-02-24 14:05:49 +00:00 by atheaadmin

Installation

registry=
npm install stylehacks@5.1.1
"stylehacks": "5.1.1"

About this package

stylehacks

Detect/remove browser hacks from CSS files.

Install

With npm do:

npm install stylehacks --save

Example

In its default mode, stylehacks will remove hacks from your CSS file, based on the browsers that you wish to support.

Input

h1 {
    _color: white;
    color: rgba(255, 255, 255, 0.5);
}

Output

h1 {
    color: rgba(255, 255, 255, 0.5);
}

API

stylehacks.detect(node)

Type: function
Returns: boolean

This method will take any PostCSS node, run applicable plugins depending on its type, then will return a boolean depending on whether it found any of the supported hacks. For example, if the decl node found below is passed to the detect function, it will return true. But if the rule node is passed, it will return false instead.

h1 { _color: red }

postcss([ stylehacks(opts) ])

stylehacks can also be consumed as a PostCSS plugin. See the documentation for examples for your environment.

options

lint

Type: boolean
Default: false

If lint mode is enabled, stylehacks will not remove hacks from the CSS; instead, it will add warnings to Result#messages.

stylehacks works well with your existing PostCSS setup:

  • stylelint - Comprehensive & modern CSS linter, to ensure that your code style rules are respected.

Contributing

Pull requests are welcome. If you add functionality, then please add unit tests to cover it.

License

MIT © Ben Briggs

Dependencies

Dependencies

ID Version
browserslist ^4.21.4
postcss-selector-parser ^6.0.4

Development Dependencies

ID Version
postcss ^8.2.15

Peer Dependencies

ID Version
postcss ^8.2.15

Keywords

browsers css hack hacks optimise postcss postcss-plugin stylehacks
Details
npm
2026-02-24 14:05:49 +00:00
1
Ben Briggs
MIT
latest
7.2 KiB
Assets (1)
Versions (1) View all
5.1.1 2026-02-24