Gathering detailed insights and metrics for postcss-pxtorem
Gathering detailed insights and metrics for postcss-pxtorem
Gathering detailed insights and metrics for postcss-pxtorem
Gathering detailed insights and metrics for postcss-pxtorem
@types/postcss-pxtorem
TypeScript definitions for postcss-pxtorem
@minko-fe/postcss-pxtorem
A postcss plugin that converts px to rem.
postcss-rem-to-responsive-pixel
Convert rem units to px or rpx units using PostCSS. Based on postcss-pxtorem and postcss-rem-to-pixel, and rewrite with typescript, and support Postcss8
postcss-pxtorem-multi
A CSS post-processor that supports multiple rules to converts px to rem based on postcss-pxtorem.
Convert pixel units to rem (root em) units using PostCSS
npm install postcss-pxtorem
Typescript
Module System
Node Version
NPM Version
98.8
Supply Chain
99.5
Quality
75.9
Maintenance
100
Vulnerability
100
License
JavaScript (96.82%)
CSS (3.18%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2,112 Stars
66 Commits
175 Forks
13 Watchers
3 Branches
9 Contributors
Updated on May 11, 2025
Minified
Minified + Gzipped
Latest Version
6.1.0
Package Id
postcss-pxtorem@6.1.0
Unpacked Size
30.02 kB
Size
7.28 kB
File Count
12
NPM Version
8.5.4
Node Version
20.10.0
Published on
Jan 20, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
6
A plugin for PostCSS that generates rem units from pixel units.
1$ npm install postcss postcss-pxtorem --save-dev
Pixels are the easiest unit to use (opinion). The only issue with them is that they don't let browsers change the default font size of 16. This script converts every px value to a rem from the properties you choose to allow the browser to set the font size.
With the default settings, only font related properties are targeted.
1// input 2h1 { 3 margin: 0 0 20px; 4 font-size: 32px; 5 line-height: 1.2; 6 letter-spacing: 1px; 7} 8 9// output 10h1 { 11 margin: 0 0 20px; 12 font-size: 2rem; 13 line-height: 1.2; 14 letter-spacing: 0.0625rem; 15}
1var fs = require('fs'); 2var postcss = require('postcss'); 3var pxtorem = require('postcss-pxtorem'); 4var css = fs.readFileSync('main.css', 'utf8'); 5var options = { 6 replace: false 7}; 8var processedCss = postcss(pxtorem(options)).process(css).css; 9 10fs.writeFile('main-rem.css', processedCss, function (err) { 11 if (err) { 12 throw err; 13 } 14 console.log('Rem file written.'); 15});
Type: Object | Null
Default:
1{ 2 rootValue: 16, 3 unitPrecision: 5, 4 propList: ['font', 'font-size', 'line-height', 'letter-spacing'], 5 selectorBlackList: [], 6 replace: true, 7 mediaQuery: false, 8 minPixelValue: 0, 9 exclude: /node_modules/i 10}
rootValue
(Number | Function) Represents the root element font size or returns the root element font size based on the input
parameterunitPrecision
(Number) The decimal numbers to allow the REM units to grow to.propList
(Array) The properties that can change from px to rem.
*
to enable all properties. Example: ['*']
*
at the start or end of a word. (['*position*']
will match background-position-y
)!
to not match a property. Example: ['*', '!letter-spacing']
['*', '!font*']
selectorBlackList
(Array) The selectors to ignore and leave as px.
['body']
will match .body-class
[/^body$/]
will match body
but not .body
replace
(Boolean) Replaces rules containing rems instead of adding fallbacks.mediaQuery
(Boolean) Allow px to be converted in media queries.minPixelValue
(Number) Set the minimum pixel value to replace.exclude
(String, Regexp, Function) The file path to ignore and leave as px.
'exclude'
will match \project\postcss-pxtorem\exclude\path
/exclude/i
will match \project\postcss-pxtorem\exclude\path
function (file) { return file.indexOf('exclude') !== -1; }
unit
(String) Set the default unit to convert, default is px
.1var gulp = require('gulp'); 2var postcss = require('gulp-postcss'); 3var autoprefixer = require('autoprefixer'); 4var pxtorem = require('postcss-pxtorem'); 5 6gulp.task('css', function () { 7 8 var processors = [ 9 autoprefixer({ 10 browsers: 'last 1 version' 11 }), 12 pxtorem({ 13 replace: false 14 }) 15 ]; 16 17 return gulp.src(['build/css/**/*.css']) 18 .pipe(postcss(processors)) 19 .pipe(gulp.dest('build/css')); 20});
Currently, the easiest way to have a single property ignored is to use a capital in the pixel unit declaration.
1// `px` is converted to `rem` 2.convert { 3 font-size: 16px; // converted to 1rem 4} 5 6// `Px` or `PX` is ignored by `postcss-pxtorem` but still accepted by browsers 7.ignore { 8 border: 1Px solid; // ignored 9 border-width: 2PX; // ignored 10}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
5 existing vulnerabilities detected
Details
Reason
Found 7/22 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More