DevNotes
@devnotes ·
HTML Part 5: Structure a whole page
You know the pieces now, so let's build a complete page, with tags that say what each area of it is for.
div and span
<div> is a box for grouping things, and <span> wraps a few words inside a line. Neither means anything on its own. They're there so you can group things and style them with CSS.
Tags with a job
For the big areas of a page, HTML has tags that describe what they're for:
<header>: the top of the page, usually the logo and menu<nav>: a group of main links<main>: the main content. Only one per page.<section>: a part of the page about one topic, usually with its own heading<article>: something that makes sense on its own, like a blog post or a product card<aside>: side content, like related links<footer>: the bottom of the page
They look exactly like a <div> until you style them. The difference is meaning. A screen reader can jump straight to <main> or <nav>, search engines understand the page better, and when you open your code again in three months, <nav> tells you a lot more than <div class="thing">.
class and id
Both are attributes you can put on any element:
idnames one element. Each id can appear only once on a page.classnames a group. Many elements can share a class, and one element can have several:class="card featured".
CSS uses them to pick what to style, and JavaScript uses them to find elements. You'll use classes far more than ids.
A whole page
The <div class="projects"> around the cards is there for the CSS series, which lays them out as a grid.
It looks plain in a browser, and that's fine. The structure is done, and CSS will take care of the looks.
Check your HTML
Paste your code into validator.w3.org, on its "Validate by Direct Input" tab. It points out unclosed tags, repeated ids and other mistakes the browser quietly forgives. Make it a habit before you move on.
Try it
Build your own version of this page with your real projects, even the small ones. You'll style this same page in the CSS series, so keep the file.
Next: CSS Part 1: How CSS styles a page
Join WIK to like and reply to DevNotes and see more like this.