sign() CSS function

Baseline 2025
Newly available

Since June 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The sign() CSS function contains one calculation, and returns -1 if the numeric value of the argument is negative, +1 if the numeric value of the argument is positive, 0⁺ if the numeric value of the argument is 0⁺, and 0⁻ if the numeric value of the argument is 0⁻.

Note: While abs() returns the absolute value of the argument, sign() returns the sign of the argument.

Syntax

css
/* property: sign( expression ) */
top: sign(20vh - 100px);

Parameters

The sign(x) function accepts only one value as its parameter.

x

A calculation which resolves to a number.

Return value

A number representing the sign of A:

  • If x is positive, returns 1.
  • If x is negative, returns -1.
  • If x is positive zero, returns 0.
  • If x is negative zero, returns -0.
  • Otherwise, returns NaN.

Formal syntax

<sign()> = 
sign( <calc-sum> )

<calc-sum> =
<calc-product> [ [ '+' | '-' ] <calc-product> ]*

<calc-product> =
<calc-value> [ [ '*' | / ] <calc-value> ]*

<calc-value> =
<number> |
<dimension> |
<percentage> |
<calc-keyword> |
( <calc-sum> )

<calc-keyword> =
e |
pi |
infinity |
-infinity |
NaN

Examples

Background image position

For example, in background-position positive percentages resolve to a negative length, and vice versa, if the background image is larger than the background area. Thus sign(10%) might return 1 or -1, depending on how the percentage is resolved! (Or even 0, if it's resolved against a zero length.)

css
div {
  background-position: sign(10%);
}

Position direction

Another use case is to control the position of the element. Either a positive or a negative value.

css
div {
  position: absolute;
  top: calc(100px * sign(var(--value)));
}

Specifications

Specification
CSS Values and Units Module Level 4
# sign-funcs

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
sign()
Chrome – Full support
Chrome 138 (Release date: 2025-06-24)
footnote Full support
Edge – Full support
Edge 138 (Release date: 2025-06-26)
footnote Full support
Firefox – Full support
Firefox 118 (Release date: 2023-09-26)
footnote Full support
Opera – Full support
Opera 122 (Release date: 2025-09-11)
footnote Full support
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote Full support
Chrome Android – Full support
Chrome Android 138 (Release date: 2025-06-24)
footnote Full support
Firefox for Android – Full support
Firefox for Android 118 (Release date: 2023-09-26)
footnote Full support
Opera Android – Full support
Opera Android 91 (Release date: 2025-08-19)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 138 (Release date: 2025-06-24)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
Divisions between typed values produce unitless number ("typed arithmetic")
Chrome – Full support
Chrome 140 (Release date: 2025-09-02)
footnote Full support
Edge – Full support
Edge 140 (Release date: 2025-09-05)
footnote Full support
Firefox – No support
Firefox
footnote
footnote See bug 1264520
Opera – Full support
Opera 124 (Release date: 2025-11-13)
footnote Full support
Safari – Full support
Safari 26 (Release date: 2025-09-15)
footnote Full support
Chrome Android – Full support
Chrome Android 140 (Release date: 2025-09-02)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1264520
Opera Android – Full support
Opera Android 92 (Release date: 2025-10-08)
footnote Full support
Safari on iOS – Full support
Safari on iOS 26 (Release date: 2025-09-15)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 140 (Release date: 2025-09-02)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also