Tiffany B. Brown

A web log about web development and internet culture with frequent detours into other stuff.
Links for November 17, 2006
Why Nate Robinson is my hero.

CSS line-height and valid values

Compare and validate (by activating the link) the following bits of CSS:

According to the CSS specification, valid values for line height include normal, a number, a specific length (such as pixels or ems), a percentage, or inherit.

Values such as #navigation{line-height:1.2;} and #navigation{line-height:.5;} are perfectly valid. So why does #navigation{line-height:2;} flunk the test while 2.0 passes?

The problem is ambiguity.

As with other CSS properties (border for example), ‘2′ is an ambiguous (and therefore undefined) value. Are we talking ‘2px,’ ‘2em,’ or ‘2%’?

But ‘2.0’ with its decimal point and trailing zero? That’s clearly a number, and therefore a valid line-height value.

Well sort of yes, and sort of no.

Actually, the problem is that the CSS validator has a bug (erm, thanks Laura). So while ‘2′ is ambiguous to the the W3C validator, browsers will apply the line-height accurately without the ‘.0′.

So: if you want to pass automated validation, use line-height:2.0. Otherwise line-height:2 is perfectly fine.

Related: Visual formatting model details from the CSS 2.1 specification

Share this entry:
  • TwitThis
  • Digg
  • Technorati
  • del.icio.us
  • Ma.gnolia
  • Mixx
  • NewsVine
  • Reddit
  • StumbleUpon
  • TailRank
  • Furl
  • Slashdot
  • Global Grind
  • YahooMyWeb
  • Facebook
  • Google
  • Live
  • LinkedIn
  • MySpace
previous post: Links for November 17, 2006
next post: Why Nate Robinson is my hero.