[whatwg] <h1> to <h6> in <body>

Ian Hickson ian at hixie.ch
Wed Mar 30 16:58:45 PST 2005


I've reached the point in my ambitious attempt at defining HTML's elements 
for the Web Apps spec [1] where I have to define <h1> - <h6>.

There are two big issues here:

 1. What do <h1> to <h6> mean in a <body>?

 2. What do <h1> to <h6> mean in a <section>?

The second question has already spawned a lot of mail on this list, and I 
will be replying to them soon. However, I want to first deal with the 
first question, which we have so far not addressed.

To rephrase the question a little, what would we want to put in HTML4 if 
we were writing an errata for HTML4 section 7.5.5?

Currently, that spec says:

# A heading element briefly describes the topic of the section it 
# introduces. Heading information may be used by user agents, for example, 
# to construct a table of contents for a document automatically.
#
# 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.

...from which we gather the following conformance requiremnts:

 1. 

(No, I didn't forget to fill in the list.)

So not much to start from. From common sense and current practice we can 
derive a simplistic list of things we want the definition to include:

 * Each header starts an implied section.

 * The section starts at the header and continues to the next
   header of that level or above.

 * Sections can be nested.

However, are there other rules? What happens if a header is in an <li>, 
does its section continue after its <ol>? What about if an <h2> has as its 
next sibling an <h4>, does an <h3>-level section get implied? What about 
if there are multiple <h1> elements on the page? What if there is no <h1> 
but there is an <h2>? (What if it is followed by an <h1>?) What section 
does text before the first header get associated with?

My current thinking is to define it such that the following document 
fragment works out as described:

   <body>
    <p>...</p>               (part of section started by A)
    <h1>A</h1>                      A
    <h2>B</h2>               1.     B
    <h3>C</h3>               1.1.   C
    <h2>D</h3>               2.     D
    <h3>E</h3>               2.1.   E
    <p>...</p>               (part of section started by E)
    <ol>                     (part of section started by E)
     <li><h3>F</h3></li>     2.2.   F
     <li><h3>G</h3></li>     2.3.   G
     <li><h3>H</h3></li>     2.4.   H
    </ol>                    (part of section started by H)
    <p>...</p>               (part of section started by H)
    <h4>I</h4>               2.4.1  I
    <h2>J</h2>               3.     J
    <div>                    (part of section started by J)
     <p>...</p>              (part of section started by J)
     <h2>K</h2>              4.     K
     <p>...</p>              (part of section started by K)
    </div>                   (part of section started by K)
    <p>...</p>               (part of section started by K)
    <h3>L</h3>               4.1.   L
    <h2>M</h2>               5.     M
    <h4>N</h4>               5.0.1. N
    <h3>O</h3>               5.1.   O
    <h1>P</h1>                      P (new section after A)
    <h1>Q</h1>                      Q (new section after P)
    <h2>R</h2>               1.     R
   </body>

The outline would be:

  Document
    |
    +-- A
    |   |
    |   +-- 1. B
    |   |   |
    |   |   +-- 1.1 C
    |   |
    |   +-- 2. D
    |   |   |
    |   |   +-- 2.1 E
    |   |   |
    |   |   +-- 2.2 F
    |   |   |
    |   |   +-- 2.3 G
    |   |   |
    |   |   +-- 2.4 H
    |   |       |
    |   |       +-- 2.4.1 I
    |   |
    |   +-- 3. J
    |   |
    |   +-- 4. K
    |   |   |
    |   |   +-- 4.1 L
    |   |
    |   +-- 5. M
    |       |
    |       +-- 5.0 <untitled>
    |       |   |
    |       |   +-- 5.0.1 N
    |       |
    |       +-- 5.1 O
    |
    +-- P
    |
    +-- Q
        |
        +-- 1. R

Any objections? Any other edge cases that I have forgotten?


[1] http://whatwg.org/specs/web-apps/current-work/#semantics

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list