The Default Styles for HTML5 as per the W3C spec can be found here
Now, from the above spec, the default styling for the h1
and h2
tag is the following:
h1 { margin-top: 0.67em; margin-bottom: 0.67em; font-size: 2.00em; font-weight: bold; }
h2 { margin-top: 0.83em; margin-bottom: 0.83em; font-size: 1.50em; font-weight: bold; }
So by default the h1
tag has font-size: 2.00em;
and h2
tag has font-size:1.5em
So far so good.
If however the h1
tag is nested within article
, aside
, nav
, or section
elements - then the h1
is rendered differently:
The following is the relevant section from the spec: (bold is mine)
The article
, aside, nav
, and section elements are expected to affect
the margins and font size of h1
elements, as well as h2–h5 elements
that follow h1
elements in hgroup elements, based on the nesting
depth.
If x
is a selector that matches elements that are either
article
, aside, nav
, or section elements, then the following rules
capture what is expected:
@namespace url(http://www.w3.org/1999/xhtml);
x h1 { margin-top: 0.83em; margin-bottom: 0.83em; font-size: 1.50em; }
x x h1 { margin-top: 1.00em; margin-bottom: 1.00em; font-size: 1.17em; }
x x x h1 { margin-top: 1.33em; margin-bottom: 1.33em; font-size: 1.00em; }
x x x x h1 { margin-top: 1.67em; margin-bottom: 1.67em; font-size: 0.83em; }
x x x x x h1 { margin-top: 2.33em; margin-bottom: 2.33em; font-size: 0.67em; }
Notice that when the h1
tag is nested 1 level within a section
or aside
etc. it gets by default font-size:1.5em
.
This explains why the h1
element within a section
or aside
element has the same font-size
as the h2
element (1.5em) as described in the question.
Now if the h1
element has a greater level of nesting within section
, aside
(or nav
or article
) elements then the h1 element gets smaller and smaller font sizes.
To illustrate this take a look at this fiddle, here, because the h1
is nested within both an article
and a section
- it is rendered even smaller than the h2
by the HTML5 default styling.
<h1>heading 1</h1>
<h2>heading 2</h2>
<h3>heading 3</h3>
<hr />
<section>
<h1>heading 1</h1>
<h2>heading 2</h2>
<h3>heading 3</h3>
</section>
<hr />
<article>
<section>
<h1>heading 1 - Nested by 2 levels - *smaller* than h2 !!</h1>
<h2>heading 2</h2>
<h3>heading 3</h3>
</section>
</article>