Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When setting CSS font-size in pixels, does the value refer to the width or height of a letter?

Tags:

html

css

Does the pixel value of a font-size refer to the height of the font or the width of the font?

CSS:

.sixteen {   font-size: 16px; } 

HTML:

<span class='sixteen'>a</span> 

Will the "a" be 16 pixels tall or 16 pixels wide, or is that like a max-width/height on both so that the entire character fits in a 16px box?

All the documentation I have seen for this has been ambiguous on the matter.

like image 509
Stephen Sorensen Avatar asked Apr 27 '12 15:04

Stephen Sorensen


People also ask

Is font-size pixels the height?

A pixel (px) at 96DPI (dots per inch) is equal to 0.2645835‬ millimeters, 0.010416675‬ inches, or 0.75 point. It is a measurement of how tall a font is in pixels which are visible on your computer screen.

What does font-size in pixels mean?

Font size specifications may come in points or pixels where: 1 pixel (px) is usually assumed to be 1/96th of an inch. 1 point (pt) is assumed to be 1/72nd of an inch. Therefore 16px = 12pt.

How are pixels measured in CSS?

The CSS pixel (px)The reference pixel is the visual angle of one pixel on a device with a pixel density of 96 DPI and a distance from the reader of an arm's length. The proper dimension of a CSS pixel is actually dependent on the distance between you and the display.


2 Answers

The height - specifically from the top of the ascenders (e.g., 'h' or 'l' (el)) to the bottom of the descenders (e.g., 'g' or 'y'). See the interesting article on Type Anatomy at http://en.wikipedia.org/wiki/Typeface_anatomy.

like image 171
D Mac Avatar answered Oct 11 '22 23:10

D Mac


The font-size property specifies the size of the font, no matter what unit is used. The size of a font can be characterized as the height of the font, but even this is just a loose and pragmatic description; characters may extend above and below the levels defined by the size of the font. The size is a more or less abstract property, and it should not be expected to correspond to the height (still less the width) of any character.

In particular, it would be all wrong to design a font where the letter “a” occupies the full height of the font. The height of “a” is typically about half of the font size, but this surely varies by font (try testing with “a” in Times New Roman and in Verdana, using the same font size).

like image 31
Jukka K. Korpela Avatar answered Oct 11 '22 23:10

Jukka K. Korpela