Semantic HTML and forms
Use elements for what they mean, not how they look, and collect data with accessible forms.
Semantic HTML means choosing the element that describes the content. Search engines and screen readers use that meaning, and your code is easier to read.
| Instead of | Use |
|---|---|
| A bold large div for a title | <h1> to <h6> in order |
| A div with links | <nav> |
| A div for the main content | <main> (one per page) |
| A div for a self-contained post | <article> |
| A styled span that acts as a button | <button> |
CarefulDo not choose a heading level for its size. Use one <h1> per page and go down one level at a time. Change the size with CSS.
Images
<img src="team.webp" alt="Three people at a whiteboard" width="800" height="450">The alt text describes the image for people who cannot see it. Set width and height so the browser reserves the space and the page does not jump while loading.
Forms
<form action="/subscribe" method="post">
<label for="email">Email</label>
<input id="email" name="email" type="email" required>
<button type="submit">Subscribe</button>
</form>Every input needs a <label> linked with for and id. The type gives you the right keyboard on phones and free validation. name is the key sent to the server.
Test yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.