githubEdit

PostCSS Custom Media

NPM Versionarrow-up-right CSS Standard Statusarrow-up-right Build Statusarrow-up-right Support Chatarrow-up-right

PostCSS Custom Mediaarrow-up-right lets you use Custom Media Queries in CSS, following the CSS Media Queriesarrow-up-right specification.

@custom-media --small-viewport (max-width: 30em);

@media (--small-viewport) {
  /* styles for small viewport */
}

/* becomes */

@media (max-width: 30em) {
  /* styles for small viewport */
}

Usage

Add PostCSS Custom Mediaarrow-up-right to your project:

npm install postcss-custom-media --save-dev

Use PostCSS Custom Mediaarrow-up-right to process your CSS:

const postcssCustomMedia = require('postcss-custom-media');

postcssCustomMedia.process(YOUR_CSS /*, processOptions, pluginOptions */);

Or use it as a PostCSSarrow-up-right plugin:

PostCSS Custom Mediaarrow-up-right runs in all Node environments, with special instructions for:

Options

preserve

The preserve option determines whether custom media and atrules using custom media should be preserved in their original form.

importFrom

The importFrom option specifies sources where custom media can be imported from, which might be CSS, JS, and JSON files, functions, and directly passed objects.

Multiple sources can be passed into this option, and they will be parsed in the order they are received. JavaScript files, JSON files, functions, and objects will need to namespace custom media using the customMedia or custom-media key.

exportTo

The exportTo option specifies destinations where custom media can be exported to, which might be CSS, JS, and JSON files, functions, and directly passed objects.

Multiple destinations can be passed into this option, and they will be parsed in the order they are received. JavaScript files, JSON files, and objects will need to namespace custom media using the customMedia or custom-media key.

See example exports written to CSSarrow-up-right, JSarrow-up-right, MJSarrow-up-right, and JSONarrow-up-right.

Last updated