Socket
Book a DemoInstallSign in
Socket

@csstools/custom-units

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@csstools/custom-units

Use Custom Units in CSS

latest
npmnpm
Version
0.1.1
Version published
Maintainers
2
Created
Source

PostCSS Custom Units

PostCSS Custom Units

PostCSS Custom Units lets you use custom units in CSS, following the CSSWG Proposal.

:root {
  /** Step (approximately 4px when 1rem is 16px) */
  --step: .25rem;

  /** Relative Pixel (approximately 1px when 1rem is 16px) */
  --rpx: .0625rem;
}

.my-component {
  font-size: 24--rpx;
  padding-inline: 3--step;
}

/* becomes */

:root {
  /** Step (approximately 4px when 1rem is 16px) */
  --step: .25rem;

  /** Relative Pixel (approximately 1px when 1rem is 16px) */
  --rpx: .0625rem;
}

.my-component {
  font-size: max(24 * var(--rpx));
  padding-inline: max(3 * var(--step));
}

Usage

Add PostCSS Custom Units to your project:

npm install @csstools/custom-units --save-dev

Use PostCSS Custom Units to process your CSS:

const postcssCustomUnits = require('@csstools/custom-units');

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

Or use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssCustomUnits = require('@csstools/custom-units');

postcss([
  postcssCustomUnits(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

FAQs

Package last updated on 02 Aug 2022

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