Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting <article> and <h1> tags?

Question:

Which of these is the proper way to nest the <h1> and <article> tags, and what is your reasoning behind it?

Choice A:

<article>
    <h1>Some Title</h1>
    <p>Here's some text and whatnot.</p>
    <p>Here's another paragraph filled with other text and other whatnots.</p>
</article>

Choice B:

<div class="post">
    <h1>Here's a Really Awesome Title</h1>
    <article>
        <p>Here's a paragraph with text and whatnot.</p>
        <p>And here's another paragraph. I think this one is pretty awesome too.</p>
    </article>
</div>

Opinions seem mixed about this, and I'm not 100% which is the correct answer.

like image 912
Nick Anderegg Avatar asked Jan 21 '11 21:01

Nick Anderegg


1 Answers

Warning

This answer is severely out-of-date and relies on the now-obsolete document outline algorithm.

both are fine

@David Dorward has a great answer, and I was going to comment to expand on it, but when I realized my comment was getting too long I decided I'd just add my own answer instead.

The h# elements semantically belong to their parents.

This h1 is the primary header for the page

<body>
  <h1>Some text</h1>
</body>

While this h1 is the primary header for the article

<body>
  <article>
    <h1>Some text</h1>
  </article>
</body>

This allows us to expand the usage of h# elements in meaningful ways as follows:

<body>
  <h1>Blag Tottle</h1>
  <article>
    <h1>Article 1 Title</h1>
    <p>Lorem ipsum etc</p>
  </article>
  <article>
    <h1>Article 2 Title</h1>
    <p>Lorem ipsum etc</p>
  </article>
</body>

Now you may want to separate your article heading some more, which is a perfect application of the header element:

<body>
  <h1>Blag Tottle</h1>
  <article>
    <header>
      <h1>Article 1 Title</h1>
      <span class="author">And not a mouse</span>
    </header>
    <p>Lorem ipsum etc</p>
  </article>
  <article>
    <header>
      <h1>Article 2 Title</h1>
      <span class="author">Somebody</span>
    </header>
    <p>Lorem ipsum etc</p>
  </article>
</body>
like image 108
zzzzBov Avatar answered Oct 21 '22 05:10

zzzzBov