6. Page Layout: div, section, header and footer

To group content into blocks you use container tags. A div is a generic box. Semantic tags give the box a meaning: header, nav, main, section, article, aside and footer. They look the same as a div by default, but they make pages clearer and more accessible. Use the class attribute to name groups of elements so CSS can style them, and id for one unique element.

Key points

  • Use semantic tags first, and div only when nothing fits.
  • class can be used on many elements; id must be unique on a page.
  • One element can have several classes separated by spaces.
  • This structure is exactly what you will see in _Layout.cshtml.

Example: A simple page layout

HTML and CSS Open in editor
<header>
  <h1>My Site</h1>
  <nav>Home | About | Contact</nav>
</header>

<main>
  <section class="card">
    <h2>Welcome</h2>
    <p>The main content goes here.</p>
  </section>
</main>

<footer>
  <p>Copyright 2026</p>
</footer>

<style>
  header, footer { background: black; color: white; padding: 12px; }
  .card { border: 2px solid black; padding: 12px; margin: 12px 0; }
</style>
Show explanation

The header, main and footer describe the page parts. The class named card is styled by the CSS rule that starts with a dot.

Try it yourself

Edit the code below and press Run. The result appears in the preview underneath.

Editor
Reset Preview runs in a safe sandbox. Scripts are disabled.
PREVIEW