100

quick question: is it actually allowed to use the header tag twice? e.g. i have two important head-sections in my header.php where both could have header tag?

pixelfreak
  • 17,714
  • 12
  • 90
  • 109
matt
  • 42,713
  • 103
  • 264
  • 397

6 Answers6

112

Yes, but with a catch. The W3 documents state that the tags represent the header and footer areas of their nearest ancestor section. I would recommend having as many as your want, but only 1 of each for each "section" of your page, i.e. body, section etc.

From W3

A header element is intended to usually contain the section's heading (an h1–h6 element or an hgroup element), but this is not required. The header element can also be used to wrap a section's table of contents, a search form, or any relevant logos.

=========================

The footer element represents a footer for its nearest ancestor sectioning content or sectioning root element. A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.

Here are links to their respective standard documentation: header and footer

linusthe3rd
  • 3,455
  • 3
  • 28
  • 43
  • 4
    I don’t agree with your catch. It’s still valid (and can also make sense) to have several `header` elements in one sectioning content/root element. – unor Mar 13 '14 at 18:30
  • What about nested sections and (therefore) nested headers in sections ? `

    ...

    ...

    `
    – Cyril Duchon-Doris Feb 28 '17 at 14:11
  • @Cyril Duchon-Doris, No a `
    ` element can not be a descendent of another `
    ` element. "Permitted parents: Any element that accepts flow content. Note that a
    element must not be a descendant of an
    ,
    or another
    element." - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header
    – Daniel Tonon Apr 17 '18 at 07:50
  • 2
    FYI, there are 5 types of "sectioning" elements: ``, ` – Daniel Tonon Apr 17 '18 at 07:58
  • 2
    @DanielTonon 1. `` is *NOT* a section element according to [this page](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_HTML_sections_and_outlines). 2. Unless there is explicit documentation that only one `
    ` and one `
    ` is permitted per section element, it's just your opinion. Please don't state like it's a rule.
    – funct7 Nov 22 '19 at 06:41
  • Ok yeah, `` isn't a "sectioning element", but it does form the default document section and is categorised as a "sectioning root" element which makes it very similar to a sectioning element in how it behaves. I did miss speak when I said that it "is" a sectioning element though. – Daniel Tonon Nov 22 '19 at 06:57
17

Yes you can use multiple header elements in your documents, by virtue of the w3c documentation:

A header element is intended to usually contain the section's heading (an h1–h6 element or an hgroup element), but this is not required. The header element can also be used to wrap a section's table of contents, a search form, or any relevant logos.

However ensure that it is semantically correct.

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
Marcus Whybrow
  • 19,578
  • 9
  • 70
  • 90
4

There's no penalty for using two header tags, but make sure it makes sense.

Happy coding!

Horia Dragomir
  • 2,858
  • 24
  • 21
2

In some situation, it is posible put two <header> in single <article>/<section> like this, so why not.

 <article>

      <!-- Feature Image on the LEFT -->
      <div class="position-left">
         ...featrue image...
        <header>
        ...H1 title ...  
        </header>
      </div>

      <!-- Content on the RIGHT with subtitle, date, etc -->
      <div class="position-right">
        <header>
          ..date, sub-title, etc...
        </header>
        ...content...
        <footer>..</footer>
      </div>

    </article>
iMarshal
  • 76
  • 8
2

The <header> is used to mark the header of e.g. articles in newspaper, so if you have multiple articles you can use multiple <header>.

It's like using multiple <h1>. It does only make sense in some special case.

Floern
  • 33,559
  • 24
  • 104
  • 119
-3

You can put two <header> tags in your document, sure. Semantically, however, it is incorrect. Why not use one <header> tag and use a different tag inside it?

Scott M.
  • 7,313
  • 30
  • 39
  • 2
    If I do this, the header would englobe all my sections, >> I don't think this is want we want... ;) You can have a header and a footer per section. – user1855153 Nov 27 '13 at 17:27