Search code examples
csspropertieszero

'property: 0' or 'property: 0px' in CSS?


I've seen this notation used a lot, and I was wondering, is there is any notable difference between these two notations?

element#id
{
  property: 0;
}

and

element#id
{
  property: 0px;
}

I use property: 0px; all the time, as I find it cleaner looking, but I'm not really sure if the browser interprets 0px differently than 0.

Does anyone know which one is better or correct?


Solution

  • While the unit is optional when the value is 0, I tend to leave it in, as I can then tweak the values with Chrome's Developer Tools by clicking on the value and pressing the up/down arrow keys. Without a unit, that isn't really possible.

    Also, CSS minifiers strip the units off of 0 values anyways, so it won't really matter in the end.