Socket
Socket
Sign inDemoInstall

postcss-env-function

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-env-function

Use env() variables in CSS


Version published
Maintainers
0
Created

What is postcss-env-function?

The postcss-env-function package is a PostCSS plugin that allows you to use environment variables in your CSS. This can be particularly useful for setting values that may change depending on the environment, such as colors, sizes, or other design tokens.

What are postcss-env-function's main functionalities?

Using environment variables in CSS

This feature allows you to define CSS variables that can be set using environment variables. The `env()` function takes the name of the environment variable and an optional fallback value.

/* CSS */
:root {
  --main-bg-color: env(MAIN_BG_COLOR, #fff);
}

body {
  background-color: var(--main-bg-color);
}

/* JavaScript to set environment variable */
process.env.MAIN_BG_COLOR = '#f0f0f0';

Fallback values

You can provide fallback values for environment variables in case they are not set. This ensures that your CSS will still have a valid value even if the environment variable is missing.

/* CSS */
:root {
  --main-text-color: env(MAIN_TEXT_COLOR, #000);
}

p {
  color: var(--main-text-color);
}

/* JavaScript to set environment variable */
process.env.MAIN_TEXT_COLOR = '#333';

Other packages similar to postcss-env-function

Keywords

FAQs

Package last updated on 03 Aug 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc