HTML — The basics

Guide 02 / 4

HTML essentials

An annotated cheat sheet: what each element is for, how to write it and when to use it.

Expected outcome :

Choose and use the essential elements to complete this step of the blog.

Reading
0%

01 · The document skeleton

Write the foundations before the visible content.

doctype, html and lang

The doctype asks the browser for standards mode. html is the root; lang="fr" announces French-language content.

<!doctype html>
<html lang="fr">
  <!-- head puis body -->
</html>

head, charset and viewport

head holds information about the document. UTF-8 allows accented characters. The viewport adapts the reference width to mobile screens.

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>À table !</title>
</head>

body, header, nav, main and footer

body contains the displayed content. header introduces the site, nav gathers the main links, main carries the main content and footer concludes the page.

<body>
  <header><h1>À table !</h1></header>
  <nav aria-label="Navigation principale"><a href="#recettes">Recettes</a></nav>
  <main id="recettes"><h2>Nos recettes</h2></main>
  <footer><p>Projet pédagogique</p></footer>
</body>
Remember :

For this project, keep a single visible main and a single h1.

section and article

section groups a theme with a heading. article is self-contained content, such as a recipe that could be shared separately.

<section aria-labelledby="titre-recettes">
  <h2 id="titre-recettes">Nos recettes</h2>
  <article><h3>Soupe de carottes</h3><p>20 minutes.</p></article>
</section>

02 · Writing the recipes

Match each piece of content with the element that describes its function.

p, strong and em

p is a paragraph. strong marks importance; em marks emphasis. Do not use them merely to get bold or italic text.

<p>Préparation : <strong>20 minutes</strong>. Servir <em>bien chaud</em>.</p>

ul, ol and li

ul suits ingredients, whose order is free. ol suits steps, which follow an order. Each list item is an li.

<h4>Ingrédients</h4>
<ul><li>4 carottes</li><li>500 ml d’eau</li></ul>
<h4>Préparation</h4>
<ol><li>Couper les légumes.</li><li>Cuire et mixer.</li></ol>

a, href and anchors

The # character followed by an id targets a place in the document. The link text must announce its destination.

<a href="#soupe">Lire la soupe de carottes</a>
<article id="soupe"><h3>Soupe de carottes</h3></article>

img, figure and figcaption

img inserts an image; figure can group it with a figcaption caption. width and height give the intrinsic dimensions and reserve space.

<figure>
  <img src="images/soupe.jpg" alt="Soupe de carottes avec du persil" width="800" height="600">
  <figcaption>Notre soupe prête à être dégustée.</figcaption>
</figure>
Remember :

Optional example: first add your own photo at this spot. CSS will then adapt it to the screen.

03 · Preparing the interactions

HTML creates the controls; the processing will be added later.

form, method, action and name

action is the address that receives the form; method indicates how it is sent. name is the name of the field sent. GET puts the values in the URL and suits a search.

<form action="" method="get">
  <label for="q">Rechercher</label>
  <input type="search" id="q" name="q">
  <button type="submit">Rechercher</button>
</form>
Remember :

This fragment adds ?q=… to the URL but does not filter anything yet. Filtering will come with JavaScript, then PHP.

select, option and button types

select presents a list of choices. option defines each value. A reset button restores the form's initial values.

<label for="duree-max">Durée maximale</label>
<select id="duree-max" name="duree">
  <option value="0">Toutes</option>
  <option value="20">20 minutes</option>
</select>
<button type="reset">Réinitialiser</button>

data-* and hidden

data-* attributes carry small pieces of data useful to the script. hidden hides an element that is not relevant for the moment.

<article class="recette" data-titre="Soupe de carottes" data-duree="20">…</article>
<p id="aucun" hidden>Aucune recette trouvée.</p>
Remember :

In the complete file, the filter form is hidden until the JavaScript course. The recipes stay visible without a script.