PostCSS Time Machine
PostCSS Time Machine fixes mistakes in the design of CSS itself, as described by the CSSWG.
They specifically requested that these should be corrected “if anyone invents a time machine”.
npx postcss-time-machine SOURCE.css TRANSFORMED.css
Safe Fixes
These fixes do not change the way CSS normally works. They can be individually
disabled by passing their short name into the fixes
option.
border-box
Box-sizing should be
border-box
by default.
/* prepended to your css */
corner-radius
border-radius
should becorner-radius
.
/* becomes */
current-color
currentcolor
should becurrent-color
.
/* becomes */
display-type
The
display
property should be calleddisplay-type
.
/* becomes */
marker-style
The
list-style
properties should be calledmarker-style
.
/* becomes */
no-wrap
In
white-space
,nowrap
should be calledno-wrap
.
/* becomes */
overflow-wrap
word-wrap
/overflow-wrap
should not exist, andoverflow-wrap
should be a keyword onwhite-space
.
/* becomes */
rgb-hsl
rgb()
andhsl()
should have an optional fourth alpha parameter (which should use the same format as R, G, and B or S and L).
/* becomes */
text-middle
In
vertical-align
,middle
should be calledtext-middle
.
/* becomes */
z-order
z-index
should be calledz-order
ordepth
.
/* becomes */
Unsafe Fixes
These fixes change the way CSS normally works. They can be individually
enabled or disabled by passing their short name into the
fixes
option, or by setting the
useUnsafeFixes
option to false
.
background-position
background-position
andborder-spacing
(all 2-axis properties) should take vertical first, to match with the 4-direction properties likemargin
.
/* becomes */
background-size
In
background-size
, having one value should duplicate its value, not default the second one toauto
.
/* becomes */
line-height
line-height: <percentage>
should compute to the equivalentline-height: <number>
, so that it effectively inherits as a percentage not a length.
/* becomes */
link-pseudo
:link
should have had the:any-link
semantics all along.
/* becomes */
Advanced Usage
Add PostCSS Time Machine to your project:
npm install postcss-time-machine --save-dev
Use PostCSS Time Machine to process your CSS:
const postcssTimeMachine = ; postcssTimeMachine;
Or use it as a PostCSS plugin:
const postcss = ;const postcssTimeMachine = ; ;
PostCSS Time Machine runs in all Node environments, with special instructions for:
Node | PostCSS CLI | Webpack | Create React App | Gulp | Grunt |
---|
Options
fixes
The fixes
option lets you individually enable or disable individual fixes.
useUnsafeFixes
The useUnsafeFixes
option determines whether unsafe fixes will be applied or
not. Individual features passed into the fixes
option will override this. By
default, unsafe features are enabled.