Info Unit on a zero value

Why a unit on a zero length value like 0px is redundant in CSS, since zero is the same length regardless of unit.

The validator flags a zero length value written with a unit — 0px, 0em, 0%, and so on — on a property that expects a length.

Example

/* Redundant */
.box { margin-top: 0px; padding: 0em 0%; }

/* Equivalent, shorter */
.box { margin-top: 0; padding: 0; }

Why it matters

A CSS length value is a number plus a unit that together describe a distance — but zero is zero regardless of what it's measured in. 0px, 0em, and 0% all resolve to the exact same computed value, so the unit carries no information and can be dropped. This is purely a style/size convention (popularized by tools like Stylelint's length-zero-no-unit rule) rather than a correctness issue — a unit on zero doesn't break anything — but omitting it is the more common convention in hand-written and linted CSS, and shaves a few bytes in aggregate across a large stylesheet.

Frequently asked questions

Is 0px actually wrong, or just a style preference?

Just a style preference — 0px is valid CSS and renders identically to 0. This check is informational, flagging it as an opportunity for consistency/brevity rather than a bug.

Does this apply to angle or time values too, like 0deg or 0s?

No — this check specifically covers the length-value properties the validator already tracks (margin, padding, width, font-size, and similar), not angle or time units.