views:

376

answers:

6

In HTML (and in typography in general, I suppose), there appears to be some defined sizes for H1-H6 -elements.

Ie., if the baseline font size is 16px (or 100%), then h1 (w/c)ould be 2.25em (36px). And H2 (w/c)ould be 1.5em (24px). Et cetera. Where do these variables come from? The H1=36px, H2=24px, H3=21px, H4=18px, H5=16px, H6=14px, that is. (or, if you like, H1=2em, H2=1.5em, H3=1.17em, etc., the point isn't the numbers themselves, but the relation between them)

Is there some mathematical formula for them? Does it have something to do with golden ratio or fibonacci? I haven't been able to find information on this.

EDIT: to be more specific, what is the pattern; why does it go from 36 to 24 to 21, or start from 36 to begin with (or, if you like, from 2em to 1.5em to 1.17em, etc.)?

Oh, I forgot to specify where I came up with the original numbers, they're from here

+1  A: 

They are defined by each browser maker independently.

They are not uniform across browsers and are there for semantics (Large header, slightly smaller header etc...).

If you look at the HTML 4 specification for these, there no mention of how they are supposed to be styled, only that they should be. From the spec:

Visual browsers usually render more important headings in larger fonts than less important ones.

If you want these to be consistent, you should use a reset stylesheet that defines them.

Even though w3 has defined a suggested default stylesheet for HTML 4 with the following details, most browsers ignore this suggestion:

h1              { font-size: 2em; margin: .67em 0 }
h2              { font-size: 1.5em; margin: .75em 0 }
h3              { font-size: 1.17em; margin: .83em 0 }
h5              { font-size: .83em; margin: 1.5em 0 }
h6              { font-size: .75em; margin: 1.67em 0 }
h1, h2, h3, h4,
h5, h6          { font-weight: bolder }

(yes, I see no font-size: for h4)

Oded
It doesn't even go that far. It describes what browsers do, not what they should do. :)
David Dorward
Yeah the spec was written based on current practices really
Tor Valamo
I was afraid the question would be interpreted like that, for which I tried to make clear I wasn't asking about browser implementations by including the 100% and em's in there.
morbusg
+1  A: 

I think it is up to the browser, which may even even let the user define the font sizes (I remember opera doing that). The HTML spec doesn't go into much detail:

There are six levels of headings in HTML with H1 as the most important and H6 as the least. Visual browsers usually render more important headings in larger fonts than less important ones.

This is intentional since HTML is designed to describe the structure, not the presentation of the document.

Otto Allmendinger
A: 

W3C suggested a default rendering stylesheet for browsers to implement.

You'll notice that your figures differ from them. That's because browser makers have a habit of ignoring everything W3C say.

Oli
I don't think it's what the W3C suggest: instead I think it's what the W3C say they've found has been actually implemented by browsers.
ChrisW
It's difficult for browser vendors to ignore the W3C when the W3C IS the browser vendor. All browser vendors are members of the W3C and sign off on the specs.
Rob
@ChrisW, FTA: "Developers are encouraged to use it as a default style sheet in their implementations." @Rob, Doesn't mean they follow the guidelines if they later feel another value better serves their purpose.
Oli
+6  A: 

It is browser-dependant, as other say.

On the other side, there is a rule in typography to set font sizes: if the base font has size X, the larger fonts should grow exponentially; the usual way is to have sizes X*sqrt(2), X*sqrt(2)^2, X*sqrt(2)^3 and so on, but you can change the base.

However, computer fonts have some special requirements.

They used to be provided in a bitmap form only (so the sizes were fixed), and even when provided in vector form -- some formats preferred some special sizes: divisible by 2 or 5 (this was f.e. the case with Amiga's old vector fonts... Agfa Intellifont?).

Even now font engines like integer sizes more, because their hinting algorithms work better.

And people seem to got used to the values chosen because of these technical restrictions, even though font engines got much better now.

liori
Although this answer has a formula, it doesn't quite work with those numbers; ie. 24*sqrt(2) ~ 34, and not 36. Or then I misunderstood/miscalculated.
morbusg
i just learnt something
DrJokepu
@DrJokepu: if I commented every time I learned something on SO, I'd get a lot more "are you a human" pages ;-) ( http://blog.stackoverflow.com/2009/07/are-you-a-human-being/ )
Joachim Sauer
A: 

Some nominal figures:

Default style sheet for HTML 4:

  • h1: 2em
  • h2: 1.5em
  • h3: 1.17em
  • h4: 1em
  • h5: 0.83em
  • h6: 0.75em

Firefox 3 and Safari 4 (actually, WebCore):

  • h1: 2em
  • h2: 1.5em
  • h3: 1.17em
  • h4: 1em
  • h5: 0.83em
  • h6: 0.67em
KennyTM
+1  A: 

In a more general way, related sizes like this are often based on a geometric series, i.e. each successive number is bigger by a constant factor (something like 1.2, or sqrt(2)) from the previous one. There is the same kind of progression in the size of wrenches and hexagonal keys, or screw diameters, etc in mechanics, or in the A5/A4/A3… family of paper sizes.

Damien Pollet