Socket
Socket
Sign inDemoInstall

autoprefixer

Package Overview
Dependencies
13
Maintainers
1
Versions
243
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

autoprefixer

Parse CSS and add vendor prefixes to CSS rules using values from the Can I Use website


Version published
Maintainers
1
Weekly downloads
16,133,242
decreased by-24.15%

Weekly downloads

Package description

What is autoprefixer?

The autoprefixer npm package is a PostCSS plugin that parses your CSS and adds vendor prefixes to CSS rules using values from Can I Use. It is a tool that automates the process of adding vendor prefixes to CSS rules to ensure cross-browser compatibility.

What are autoprefixer's main functionalities?

Adding vendor prefixes

This feature automatically adds necessary vendor prefixes to CSS rules. The code sample shows how to use autoprefixer with PostCSS to process a CSS string that includes the 'display: flex;' rule, which then outputs the rule with the appropriate vendor prefixes.

const autoprefixer = require('autoprefixer');
const postcss = require('postcss');

postcss([ autoprefixer ]).process('a { display: flex; }').then(result => {
  console.log(result.css);
  // Output: 'a { display: -webkit-box; display: -ms-flexbox; display: flex; }'
});

Customizing browser support

Autoprefixer allows customization of the browsers you want to target. The code sample demonstrates how to specify the browsers using the 'overrideBrowserslist' option to target the last 2 versions of all browsers.

const autoprefixer = require('autoprefixer');
const postcss = require('postcss');

postcss([ autoprefixer({ overrideBrowserslist: ['last 2 versions'] }) ])
.process('a { display: flex; }').then(result => {
  console.log(result.css);
  // Output will include prefixes for the last 2 versions of all browsers.
});

Removing unnecessary prefixes

Autoprefixer can also remove outdated prefixes if they are no longer needed for the specified browser range. The code sample shows how to disable this feature using the 'remove' option.

const autoprefixer = require('autoprefixer');
const postcss = require('postcss');

postcss([ autoprefixer({ remove: false }) ])
.process('a { -webkit-box-shadow: 0 0 10px black; box-shadow: 0 0 10px black; }').then(result => {
  console.log(result.css);
  // Output will keep the -webkit-box-shadow prefix even if it's not necessary for the specified browsers.
});

Other packages similar to autoprefixer

Readme

Source

Autoprefixer Cult Of Martians

PostCSS plugin to parse CSS and add vendor prefixes to CSS rules using values from Can I Use. It is recommended by Google and used in Twitter and Alibaba.

Write your CSS rules without vendor prefixes (in fact, forget about them entirely):

::placeholder {
  color: gray;
}

.image {
  background-image: url(image@1x.png);
}
@media (min-resolution: 2dppx) {
  .image {
    background-image: url(image@2x.png);
  }
}

Autoprefixer will use the data based on current browser popularity and property support to apply prefixes for you. You can try the interactive demo of Autoprefixer.

::-moz-placeholder {
  color: gray;
}
::placeholder {
  color: gray;
}

.image {
  background-image: url(image@1x.png);
}
@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 2dppx) {
  .image {
    background-image: url(image@2x.png);
  }
}

Twitter account for news and releases: @autoprefixer.

Sponsored by Evil Martians

Docs

Read full docs on GitHub.

Keywords

FAQs

Last updated on 29 Jul 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc