Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the value of the css 'ex' unit?

(Not to be confused with Xunit, a popular .Net unit testing library.)

Today in a fit of boredom I started inspecting Gmails DOM (yes, I was very bored).

Everything looked pretty straightforward until I noticed an interesting specification on the widths of certain elements. The illustrious Googlites had specified a number of table cols using the rare 'ex' unit.

width: 22ex; 

At first I was stumped ("what's an 'ex'?"), then it came back to me: I seem to remember something from years ago when first I was learning about CSS. From the CSS3 spec:

[The ex unit is] equal to the used x-height of the first available font. The x-height is so called because it is often equal to the height of the lowercase "x". However, an ‘ex’ is defined even for fonts that do not contain an "x".

Well and good. But I've never actually seen it used before (much less used it myself). I use ems quite commonly, and appreciate their value, but why the "ex"? It seems much less standard a measurement than the em, and far less useful.

One of the few pages I found discussing this topic is Stephen Poley's http://www.xs4all.nl/~sbpoley/webmatters/emex.html. Stephen makes good points, however, his discussion seems inconclusive to me.

So my question is: What value does the 'ex' unit lend to web design?

(This question could be tagged subjective, but I'll leave that decision to more experienced SO'ers than myself.)

like image 656
Joel Avatar asked May 28 '09 00:05

Joel


People also ask

What is ex unit CSS?

The ex unit is defined as the “x-height of the current font OR one-half of one em ”. The x-height of a given font is the height of the lower-case x of that font.

How much is 1vh?

A value of 1vh is equal to 1% of the viewport height. Viewport Width (vw). This unit is based on the width of the viewport. A value of 1vw is equal to 1% of the viewport width.

What is CSS percent unit?

The <percentage> CSS data type represents a percentage value. It is often used to define a size as relative to an element's parent object. Numerous properties can use percentages, such as width , height , margin , padding , and font-size .


1 Answers

It is useful when you want to size something in relation to the height of your text's lowercase letters. For example, imagine working on a design like so:

alt text


In the typographic dimension of design, the height of letters has important spatial relationships to the rest of the elements. The lines in the source image above are intended to help point out the x-height of the text, but they also show where guidelines would be if designing around that text.

As Jonathan pointed out in the comments, ex is simply the height version of em (width).

like image 200
Rex M Avatar answered Oct 15 '22 23:10

Rex M