# sign()

> The `sign()` CSS function returns -1, 0 or 1 depending on the sign of the argument.

## What does sign() do in CSS?

The function that returns '-1' if the argument is negative, '1' if positive and '0' if zero. Allows building conditional logic in calculations, for example switching values based on custom properties.

- Topic: Mathematics
- Type: function
- Browser support: Chrome 138+, Chrome Android 138+, Edge 138+, Firefox 118+, Firefox Android 118+, Safari 15.4+, Safari iOS 15.4+

## Example

```css
.card {
  --dx: -40px;
  translate: calc(sign(var(--dx)) * 10px) 0;
}
```

`sign()` returns '-1', '0' or '1', so the card moves 10px in the direction of `--dx` whatever its size.

## Common mistakes

- Expecting a length back, while `sign()` returns -1, 0 or 1 as a plain number.

## Key points

- Values that depend on direction multiply by `sign()` instead of separate rules for each case.
- The argument can hold math directly, like `sign(100% - 400px)`.

## Interview questions

### What does sign() return for zero?

It returns 0, so anything multiplied by it becomes 0 too.

### Can sign() take lengths?

Yes. The argument can be a length or percentage, like `sign(100% - 400px)`, but the result is always a plain number.

## Related cards

- [abs()](https://wonderium.dev/css/abs.md)
- [calc()](https://wonderium.dev/css/calc.md)
- [round()](https://wonderium.dev/css/round.md)
- [clamp()](https://wonderium.dev/css/clamp.md)
- [Math.sign()](https://wonderium.dev/js/math-sign.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/sign
- Last updated: 2026-11-25
