Search code examples
cssunits-of-measurement

What is the difference between height = 2px and height = 2


What is the difference between height = 2px and height = 2? When we don't specify units like px or em what unit does it take?


Solution

  • If you are referring to HTML then it will always be pixels. If it is CSS it will be browser dependent and dependent on the element you are assigning the height to, for example line-height: 2 will represent 200% of the value of the font on that line. Current browsers assign it as an invalid value in CSS and the size should not render.