0

Possible Duplicate:
What is the value of the css 'ex' unit?

Is there a proper usage of the 'ex' unit in CSS? When should it be used/not be used instead of other units like 'px', '%', 'em'?

Community
  • 1
  • 1
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
  • 2
    Several more in the search: http://stackoverflow.com/search?q=css+ex we are always happy about good new questions, so don't feel discouraged from asking, but please as a habit do a check for existing duplicates first. Many (most?) questions already have good answers :) – Pekka Feb 17 '11 at 23:48
  • Also, after you enter the title of your question the site will automatically suggest existing questions it thinks are relevant to what you're looking for. Do peruse them first, and see if there are any existing answers you can vote on. – BoltClock Feb 17 '11 at 23:57

2 Answers2

3

I'd think ex should be used instead of em when dealing with vertical rather than horizontal measurements (e.g., height instead of width).

tomlogic
  • 11,489
  • 3
  • 33
  • 59
  • Sorry, this is simply wrong. Both ex and em are based on vertical sizes of the font. Em the height of an upper-case M, ex is the height of a lower case x. You can use both for vertical and horizontal measurements though. – JacquesB May 09 '15 at 10:46
  • Coming from a typographic background, I always think of width for `em`, especially because of the `em dash`, `en dash` and `em space`. It's true that the measurement is the same as the point size, but it isn't actually the height of the upper-case M since that doesn't take the space below the baseline into account. Check [Wikipedia](http://en.wikipedia.org/wiki/Em_(typography)) for more than you'd ever want to know about the em unit. – tomlogic May 10 '15 at 21:22
  • I initially misunderstood your comment. Yes, you are right that the "em-box" and hence the em unit is bigger than the size of an actual M, since the em-box is (a bit simplified) the bounding rectangle of all letters in the font, including ascenders and descenders. My point was just that the em unit is defined from the *height* of the em-box, not the width, and the ratio of the height to the width varies with the font. Css3 introduces a new unit, ch, which is the *width* of a character, but em and ex are both based on heights. – JacquesB May 12 '15 at 19:42
  • "Although the size of the em ultimately depends on the point size, or height of the metal body of a letter, it is also used as a measure of horizontal spacing relative to the type size…" The bottom line, for me at least, is that "em" makes me think of width, not height. The width of the dash or space, which is relative to the height (100% of height for em, 50% of height for en). – tomlogic May 13 '15 at 18:14
0

It's a pretty obscure unit. I've been a pro web developer for eight years and never used it, or even seen it used, even once.

jpsimons
  • 27,382
  • 3
  • 35
  • 45