Search code examples
htmlsemanticssemantic-markup

How exactly do the semantics of the HTML5 <header>, <section>, and <footer> tags work?


I'm a bit puzzled how I'm supposed to use the HTML5 <header>, <section>, and <footer> tags. Currently, I can't work out whether to use them like this:

<section id="example_section">
    <header>
        <h1>Example Section</h1>
        <p>etc</p>
    </header>

    <p>Content para 1</p>
    <p>Content para 2</p>
    <p>Content para 3</p>

    <footer>
        Wasn't that swell?
    </footer>
</section>

Or like this:

<header>
    <h1>Example Section</h1>
    <p>etc</p>
</header>

<section id="example_section">
    <p>Content para 1</p>
    <p>Content para 2</p>
    <p>Content para 3</p>
</section>

<footer>
    Wasn't that swell?
</footer>

Or compromising, like this:

<section id="example_section_wrapper">
    <header>
        <h1>Example Section</h1>
        <p>etc</p>
    </header>
    <section id="example_section">
        <p>Content para 1</p>
        <p>Content para 2</p>
        <p>Content para 3</p>
    </section>
    <footer>
        Wasn't that swell?
    </footer>
</section>

I've included the ID's to show the intended meaning of the sections. I realise that they are unnecessary. Which method is correct?


Solution

  • All are correct in one way another but this is more better then any other

    <section id="example_section_wrapper">
        <header>
            <h1>Example Section</h1>
            <p>etc</p>
        </header>
        <section id="example_section">
            <p>Content para 1</p>
            <p>Content para 2</p>
            <p>Content para 3</p>
        </section>
        <footer>
            Wasn't that swell?
        </footer>
    </section>
    

    Couple of best practice and tuts links