Guide 02 / 4
HTML essentials
An annotated cheat sheet: what each element is for, how to write it and when to use it.
Choose and use the essential elements to complete this step of the blog.
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.
Example
<!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.
Example
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>À table !</title>
</head>
section and article
section groups a theme with a heading. article is self-contained content, such as a recipe that could be shared separately.
Example
<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.
Example
<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.
Example
<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.
Example
<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.
Example
<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>
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.
Example
<form action="" method="get">
<label for="q">Rechercher</label>
<input type="search" id="q" name="q">
<button type="submit">Rechercher</button>
</form>
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.
Example
<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>