CSS numeric factory functions

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The CSS numeric factory functions, such as CSS.em() and CSS.turn() are methods that return CSSUnitValues with the value being the numeric argument and the unit being the name of the method used. These functions create new numeric values less verbosely than using the CSSUnitValue.CSSUnitValue() constructor.

Syntax

CSS.number(number);
CSS.percent(number);

// <length>
CSS.em(number);
CSS.ex(number);
CSS.ch(number);
CSS.ic(number);
CSS.rem(number);
CSS.lh(number);
CSS.rlh(number);
CSS.vw(number);
CSS.vh(number);
CSS.vi(number);
CSS.vb(number);
CSS.vmin(number);
CSS.vmax(number);
CSS.cm(number);
CSS.mm(number);
CSS.Q(number);
CSS.in(number);
CSS.pt(number);
CSS.pc(number);
CSS.px(number);

// <angle>
CSS.deg(number);
CSS.grad(number);
CSS.rad(number);
CSS.turn(number);

// <time>
CSS.s(number);
CSS.ms(number);

// <frequency>
CSS.Hz(number);
CSS.kHz(number);

// <resolution>
CSS.dpi(number);
CSS.dpcm(number);
CSS.dppx(number);

// <flex>
CSS.fr(number);

Examples

We use the CSS.vmax() numeric factory function to create a CSSUnitValue:

let height = CSS.vmax(50);

console.log( height );       // CSSUnitValue {value: 50, unit: "vmax"}
console.log( height.value )  // 50
console.log( height.unit )   // vmax

In this example, we set the margin on our element using the CSS.px() factory function:

myElement.attributeStyleMap.set('margin', CSS.px(40));
let currentMargin = myElement.attributeStyleMap.get('margin');
console.log(currentMargin.value, currentMargin.unit); // 40, 'px'

Specification

Specification Status Comment
CSS Object Model (CSSOM)
The definition of 'Numeric Factory Functions' in that specification.
Working Draft Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
CSS
Experimental
Chrome Full support 28Edge Full support YesFirefox Full support 22
Full support 22
Full support 20
Disabled
Disabled From version 20: this feature is behind the layout.css.supports-rule.enabled preference. To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 12.1Safari Full support 10WebView Android Full support 4.4Chrome Android Full support 28Firefox Android Full support 22
Full support 22
Full support 20
Disabled
Disabled From version 20: this feature is behind the layout.css.supports-rule.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android Full support 12.1Safari iOS Full support YesSamsung Internet Android Full support Yes
Hz
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
Q
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
ch
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
cm
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
deg
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
dpcm
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
dpi
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
dppx
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
em
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
escape
Experimental
Chrome Full support 46Edge No support NoFirefox Full support 31IE No support NoOpera Full support 33Safari Full support 10WebView Android Full support 46Chrome Android Full support 46Firefox Android Full support 31Opera Android Full support 33Safari iOS No support NoSamsung Internet Android Full support Yes
ex
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
fr
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
grad
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
ic
Experimental
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
in
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
kHz
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
lh
Experimental
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
mm
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
ms
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
number
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
paintWorklet
Experimental
Chrome Full support 65Edge No support NoFirefox ? IE No support NoOpera Full support 52Safari No support NoWebView Android Full support 65Chrome Android Full support 65Firefox Android ? Opera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
pc
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
percent
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
pt
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
px
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
rad
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
registerProperty
Experimental
Chrome Full support 78Edge No support NoFirefox No support NoIE No support NoOpera Full support 65Safari No support NoWebView Android Full support 78Chrome Android Full support 78Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
rem
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
rlh
Experimental
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
s
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
supportsChrome Full support 61
Full support 61
Partial support 28
Notes
Notes Version 60 or older didn't support parentheses-less one-argument version.
Edge Partial support 12
Notes
Partial support 12
Notes
Notes Edge doesn't support parentheses-less one-argument version.
Firefox Full support 55
Full support 55
Partial support 22
Notes
Notes Version 54 or older didn't support parentheses-less one-argument version.
Partial support 20
Disabled
Disabled From version 20: this feature is behind the layout.css.supports-rule.enabled preference. To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 12.1Safari Full support 10WebView Android Full support 61
Full support 61
Partial support 37
Notes
Notes Version 60 or older didn't support parentheses-less one-argument version.
Chrome Android Full support 61
Full support 61
Partial support 28
Notes
Notes Version 60 or older didn't support parentheses-less one-argument version.
Firefox Android Full support 55
Full support 55
Partial support 22
Notes
Notes Version 54 or older didn't support parentheses-less one-argument version.
Partial support 20
Disabled
Disabled From version 20: this feature is behind the layout.css.supports-rule.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android Full support 12.1Safari iOS Full support YesSamsung Internet Android Full support 4.0
turn
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
vb
Experimental
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
vh
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
vi
Experimental
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
vmax
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
vw
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes
wmin
Experimental
Chrome Full support 66Edge No support NoFirefox No support NoIE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support 47Safari iOS No support NoSamsung Internet Android ?

Legend

Full support Ā 
Full support
Partial support Ā 
Partial support
No support Ā 
No support
Compatibility unknown Ā 
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also