Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 705
Eric Avatar asked Feb 26 '23 04:02

Eric


2 Answers

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

  • HTML 5 and CSS 3: The Techniques You’ll Soon Be Using
  • HTML5 Overview (*best practice block)
  • Designing for the Future with HTML5+CSS3 : Tutorials and Best Practices
like image 130
Pramendra Gupta Avatar answered Mar 01 '23 11:03

Pramendra Gupta


A section can contain a section but a better general container is actuall article. Instead of 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>

You might want to use this:

<article>
    <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>
</article>

Like this it feels natural to have various sections in one article.

like image 40
emik Avatar answered Mar 01 '23 10:03

emik