Size of zero pixels in CSS with or without ‘px’ suffix? [duplicate]

They are identical.

Use width: 0, because it is shorter and more readable.

Especially when you have, for example:

padding: 0px 0px 9px 8px

vs

padding: 0 0 9px 8px

See the specs:

The format of a length value (denoted
by <length> in this specification) is
a <number> (with or without a decimal
point) immediately followed by a unit
identifier (e.g., px, em, etc.).
After a zero length, the unit identifier is optional.


The minor problem with ‘0’ is that if
you change it to some non-zero value,
you might forget to add the ‘px’. And
when making a value ‘0’, you may
forget to remove the ‘px’

This does not happen once you get into the habit of writing 0 without the unit identifier.

Leave a Comment

tech