By, by CSSNext, hello postcss-preset-env
By, by CSSNext, hello postcss-preset-env By, by CSSNext, hello postcss-preset-env By, by CSSNext, hello postcss-preset-env

As CSSNext is now deprecated you can use instead the Postcss plugin "PostCSS Preset Env" to lets you use modern CSS in your style sheet.

PostCSS Preset Env lets you transform modern CSS so most browsers can understand, determining the polyfills you need based on the browsers you want. It's essentially like Babel Preset-Env for CSS - a bundle of CSS polyfills and polyfills applied at compile time.

Core Functionality: PostCSS Preset Env takes support data from MDN and Can I Use, and determines from a browserslist whether transformations are needed. It also packs Autoprefixer within and shares the list with it, so prefixes are automatically handled.

Key Features:

1. Stage-Based Feature Support

  • The stage option determines which CSS features to polyfill, based upon their stability in the process of becoming implemented web standards, ranging from stage 0 (experimental) through 4 (stable).

  • Without any configuration, PostCSS Preset Env enables Stage 2 features and supports all browsers.

2. Feature Selection

  • The features option enables or disables specific polyfills by ID, allowing you to enable experimental features while using more stable stages.

  • Access to hundreds of modern CSS features like nesting rules, custom properties, color functions, and more

3. Browser Targeting

  • The browsers option determines which polyfills are required based upon the browsers you're supporting, using standard browserslist configuration.

  • Automatically omits polyfills for features already supported by target browsers

4. Built-in Autoprefixer

  • PostCSS Preset Env includes autoprefixer and the browsers option is passed to it automatically.

  • Eliminates need for separate autoprefixer configuration

5. Standards Compliance

  • Only packs plugins that enable features acknowledged by the World Wide Web Consortium (W3C) which will then be implemented by browsers later.

  • Helps developers write standards-compliant future CSS today

Available Features Include:

  • CSS nesting rules

  • Custom properties and media queries

  • Color functions (like alpha(), color-mod())

  • Logical properties

  • :any-link, :blank pseudo-classes

  • Break properties

  • All-property reset

  • And many more modern CSS features

Benefits:

  • Write modern CSS syntax today without browser compatibility concerns

  • Easier migration to native CSS features as browser support improves

  • More stable codebase compared to non-standard CSS preprocessors

  • Interactive playground available for testing features

  • Configurable preservation of original CSS for progressive enhancement

Target Users: Front-end developers wanting to use cutting-edge CSS features while maintaining broad browser support, similar to how Babel enables modern JavaScript usage.