Maîtriser toutes les propriétés CSS liées aux polices, au texte et à la mise en forme typographique.
La typographie est l'un des piliers fondamentaux du design web. Elle regroupe l'ensemble des propriétés qui influencent l'apparence visuelle du texte : police, taille, graisse, espacement, alignement, décorations, et bien plus.
Ce chapitre couvre toutes les propriétés CSS liées aux textes et polices, organisées en deux grandes catégories :
| Catégorie | Propriétés couvertes | Rôle principal |
|---|---|---|
| Polices (Font) | font-family, font-size, font-weight, font-style, font-variant, font-stretch, font-display, font, @font-face, Google Fonts, variable fonts | Choisir et configurer la police utilisée |
| Texte (Text) | line-height, letter-spacing, word-spacing, text-align, text-transform, text-shadow, white-space, overflow-wrap, word-break, hyphens, text-decoration, text-overflow, text-indent, vertical-align, direction | Mettre en forme le contenu textuel |
/* Font stack : la première police disponible est utilisée */
body {
font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}
/* Polices spécifiques */
.titre {
font-family: 'Georgia', 'Times New Roman', serif;
}
.code {
font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}
| Valeur | Description | Exemple |
|---|---|---|
serif |
Empattements — style traditionnel | Georgia, Times New Roman |
sans-serif |
Sans empattements — style moderne | Arial, Helvetica, Verdana |
monospace |
Chasse fixe — pour le code | Courier New, Consolas |
cursive |
Style manuscrit | Comic Sans MS |
fantasy |
Style décoratif | Impact |
system-ui |
Police du système d'exploitation | Segoe UI (Windows), SF Pro (macOS) |
inherit |
Hérite de la police du parent | — |
/* Unités absolues */
.titre { font-size: 24px; }
.petit { font-size: 10pt; }
/* Unités relatives à l'élément parent (em) */
.titre { font-size: 1.5em; }
/* Unités relatives à la racine (rem) */
.corps { font-size: 1rem; }
/* Unités视窗 (vw, vh) — responsive */
.banniere { font-size: 5vw; }
/* Pourcentages */
.sous-titre { font-size: 120%; }
/* Mots-clés */
.titre { font-size: x-large; }
.corps { font-size: medium; }
.petit { font-size: x-small; }
| Mot-clé | Valeur approximative |
|---|---|
xx-small | ~10px |
x-small | ~12px |
small | ~13px |
medium | ~16px (défaut) |
large | ~18px |
x-large | ~24px |
xx-large | ~32px |
smaller | ~80% du parent |
larger | ~120% du parent |
/* Mots-clés */
.fin { font-weight: normal; } /* = 400 */
.gras { font-weight: bold; } /* = 700 */
.leger { font-weight: lighter; } /* Plus fin que le parent */
.epais { font-weight: bolder; } /* Plus gras que le parent */
/* Valeurs numériques */
.tres-fin { font-weight: 100; }
.fin { font-weight: 200; }
.leger { font-weight: 300; }
.normal { font-weight: 400; }
.moyen { font-weight: 500; }
.semi-gras { font-weight: 600; }
.gras { font-weight: 700; }
.epais { font-weight: 800; }
.tres-epais { font-weight: 900; }
Démonstration : font-weight
font-weight: 100 — Très fin
font-weight: 300 — Léger
font-weight: 400 — Normal
font-weight: 500 — Moyen
font-weight: 700 — Gras
font-weight: 900 — Très épais
.normal { font-style: normal; } /* Défaut */
.italique { font-style: italic; } /* Vrai italique (forme spéciale) */
.oblique { font-style: oblique; } /* Version inclinée du normal */
| Valeur | Description | Quand l'utiliser |
|---|---|---|
normal |
Style normal | Défaut, texte courant |
italic |
Vrai italique (police dédiée) | Citations, termes étrangers, emphasis |
oblique |
Inclinaison mécanique | Quand la police n'a pas de vrai italique |
italic et oblique. italic utilise une version dessinée spécialement par le typographe, tandis que oblique penche simplement les caractères normaux. Utilisez italic en priorité.
/* Petites capitales */
.titre {
font-variant: small-caps;
}
/* Autres variantes */
.texte {
font-variant-ligatures: common-ligatures;
font-variant-numeric: lining-nums;
font-variant-caps: all-small-caps;
font-variant-position: super;
font-variant-alternates: stylistic(1);
}
| Propriété | Valeurs courantes |
|---|---|
font-variant |
normal, small-caps |
font-variant-ligatures |
none, common-ligatures, discretionary-ligatures |
font-variant-numeric |
lining-nums, oldstyle-nums, tabular-nums |
font-variant-caps |
normal, small-caps, all-small-caps |
font-variant-position |
normal, super, sub |
Démonstration : font-variant small-caps
Texte normal : The quick brown fox jumps over the lazy dog.
small-caps : The quick brown fox jumps over the lazy dog.
all-small-caps : The Quick Brown Fox Jumps Over The Lazy Dog.
/* Valeurs en pourcentage */
.colle { font-stretch: ultra-condensed; } /* 50% */
.etroit { font-stretch: condensed; } /* 75% */
.normal { font-stretch: normal; } /* 100% */
.large { font-stretch: expanded; } /* 125% */
.tres-large { font-stretch: ultra-expanded; } /* 200% */
/* Valeurs en pourcentage */
.texte { font-stretch: 80%; }
| Mot-clé | Valeur |
|---|---|
ultra-condensed | 50% |
extra-condensed | 62.5% |
condensed | 75% |
semi-condensed | 87.5% |
normal | 100% |
semi-expanded | 112.5% |
expanded | 125% |
extra-expanded | 150% |
ultra-expanded | 200% |
@font-face {
font-family: 'MaPolice';
src: url('mapolice.woff2') format('woff2'),
url('mapolice.woff') format('woff');
font-display: swap; /* ← La stratégie d'affichage */
}
| Valeur | Comportement | Recommandé pour |
|---|---|---|
auto |
Le navigateur choisit (comme block par défaut) |
Ne pas spécifier |
block |
Blocage invisible pendant ~3s, puis fallback, puis police | Polices critiques (titres) |
swap |
Affiche le fallback immédiatement, remplace quand la police est prête | Recommandé — le plus courant |
fallback |
Blocage très court (~100ms), puis fallback, puis remplacement | Polices importantes mais pas critiques |
optional |
Si la police n'est pas chargée instantanément, utilise le fallback sans jamais revenir | Polices non essentielles |
font-display: swap est la valeur la plus utilisée. Elle garantit que le texte est toujours visible (avec le fallback) et se remplace élégamment quand la web font arrive.
/* Syntaxe : font: [style] [variant] [weight] [stretch] size[/line-height] family; */
/* Les valeurs obligatoires sont : font-size et font-family */
/* Minimal */
body {
font: 16px/1.6 'Segoe UI', sans-serif;
}
/* Complet */
.titre {
font: italic small-caps 700 1.5rem/1.3 'Georgia', serif;
}
/* Avec line-height en pourcentage */
.paragraphe {
font: 400 1rem/150% 'Segoe UI', sans-serif;
}
font, toutes les valeurs de sous-propriétés non spécifiées sont réinitialisées à leurs valeurs par défaut. Par exemple, si vous définissez font: 16px sans-serif, le font-weight redevient normal et le line-height redevient normal.
@font-face {
font-family: 'MaPoliceTitre';
src: url('fonts/mapolice-titre.woff2') format('woff2'),
url('fonts/mapolice-titre.woff') format('woff');
font-weight: 700;
font-style: normal;
font-display: swap;
}
/* Utilisation */
h1 {
font-family: 'MaPoliceTitre', sans-serif;
}
| Descripteur | Obligatoire | Description |
|---|---|---|
font-family | Oui | Nom de la police (arbitraire) |
src | Oui | URL(s) du fichier de police + format |
font-weight | Non | Graisse de la déclaration |
font-style | Non | Style de la déclaration |
font-display | Non | Stratégie d'affichage |
unicode-range | Non | Plage de caractères à charger |
font-stretch | Non | Largeur de la police |
<!-- Méthode 1 : Balise link (recommandée — plus rapide) -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@700&display=swap" rel="stylesheet">
/* Méthode 2 : @import (plus lent, bloque le rendu) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
/* Utilisation */
body { font-family: 'Inter', sans-serif; }
h1 { font-family: 'Playfair Display', serif; }
<link> à @import pour les performances.wght) réellement utilisées.&display=swap pour éviter le FOIT (Flash of Invisible Text)./* Déclaration d'une police variable */
@font-face {
font-family: 'InterVariable';
src: url('fonts/Inter-Variable.woff2') format('woff2-variations');
font-weight: 100 900;
font-display: swap;
}
/* Utilisation */
.titre { font-weight: 800; }
.corps { font-weight: 400; }
.fin { font-weight: 200; }
/* Avec Google Fonts — ajouter le paramètre wght */
/* https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap */
Démonstration : Police variable (font-weight)
Inter — 100 (Thin)
Inter — 300 (Light)
Inter — 500 (Medium)
Inter — 700 (Bold)
Inter — 900 (Black)
/* Sans unité (recommandé : multiplicateur) */
p { line-height: 1.6; } /* 160% de la taille de police */
p { line-height: 1; } /* Pas d'espace supplémentaire */
/* Avec em — même comportement que sans unité */
p { line-height: 1.6em; } /* = 1.6 × font-size de CE calcul */
/* Avec px — valeur fixe */
p { line-height: 24px; }
/* Avec pourcentage */
p { line-height: 160%; } /* = 1.6 × font-size du calcul */
/* Mots-clés */
p { line-height: normal; } /* Défaut du navigateur (~1.2) */
Comparaison : Sans unité vs em vs px
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
line-height avec em ou % dans des éléments imbriqués peut provoquer un écartement cumulatif. Préférez toujours la valeur sans unité (ex: 1.6), qui est un multiplicateur et ne dépend pas du contexte.
/* Espacement positif — texte plus aéré */
.titre {
letter-spacing: 0.05em;
}
/* Espacement négatif — texte plus serré */
.compact {
letter-spacing: -0.02em;
}
/* En pixels */
.titre {
letter-spacing: 2px;
}
/* Réinitialisation */
.normal {
letter-spacing: normal;
}
Démonstration : letter-spacing
letter-spacing: normal — Texte normal
letter-spacing: 0.1em — Texte espacé
letter-spacing: -0.03em — Texte serré
LETTER-SPACING: 0.2em — EN MAJUSCULES
.normal { word-spacing: normal; }
.large { word-spacing: 0.5em; }
.serre { word-spacing: -0.1em; }
.gauche { text-align: left; } /* Aligné à gauche */
.droite { text-align: right; } /* Aligné à droite */
.centree { text-align: center; } /* Centré */
.justifie { text-align: justify; } /* Justifié */
/* Valeurs logiques (directionnelles) */
.debut { text-align: start; } /* Début du texte (gauche en LTR) */
.fin { text-align: end; } /* Fin du texte (droite en LTR) */
.match-parent { text-align: match-parent; } /* Hérite du parent */
Démonstration : text-align
text-align: left — Le texte est aligné à gauche du conteneur.
text-align: center — Le texte est centré dans le conteneur.
text-align: right — Le texte est aligné à droite du conteneur.
text-align: justify — Le texte est justifié, les mots sont espacés pour remplir toute la largeur du conteneur de manière uniforme.
text-align: justify peut créer des « rivières » de blanc dans les paragraphes courts. Il est déconseillé pour le texte de corps sur écran.
.majuscules { text-transform: uppercase; } /* TOUT EN MAJUSCULES */
.minuscules { text-transform: lowercase; } /* tout en minuscules */
.capitalise { text-transform: capitalize; } /* Première Lettre De Chaque Mot */
.aucun { text-transform: none; } /* Pas de transformation */
Démonstration : text-transform
Texte original : hello world → UPPERCASE
Texte original: HELLO WORLD → lowercase
Texte original: hello world → Capitalize
Texte original: Hello World → none (inchangé)
text-shadow: offsetX offsetY blur-radius color;
/* Ombre simple */
.ombre-simple {
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
/* Ombre sans flou */
.ombre-nette {
text-shadow: 2px 2px 0 #333;
}
/* Effet néon */
.neon {
text-shadow:
0 0 10px #fff,
0 0 20px #fff,
0 0 30px #e60073,
0 0 40px #e60073;
}
/* Effet embossé */
.emboss {
text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
}
/* Supprimer une ombre */
.sans-ombre {
text-shadow: none;
}
Démonstration : text-shadow
Ombre simple
Effet Néon
Effet Embossé
Lueur (glow)
| Valeur | Espaces | Retours ligne HTML | Dépassement |
|---|---|---|---|
normal |
Compressés | Ignorés | Saut de ligne |
nowrap |
Compressés | Ignorés | Pas de saut |
pre |
Préservés | Préservés | Pas de saut |
pre-wrap |
Préservés | Préservés | Saut de ligne |
pre-line |
Compressés | Préservés | Saut de ligne |
break-spaces |
Préservés | Préservés | Saut partout |
.normal { white-space: normal; } /* Comportement par défaut */
.pas-sauter { white-space: nowrap; } /* Pas de retour à la ligne */
.pre { white-space: pre; } /* Comme <pre> HTML */
.pre-wrap { white-space: pre-wrap; } /* Préserve les espaces + wrap */
.pre-line { white-space: pre-line; } /* Préserve les retours HTML + wrap */
Démonstration : white-space
Ceci préserve les espaces et les retours à la ligne.
Ceci préserve les espaces mais ajoute des retours à la ligne quand c'est nécessaire.
/* overflow-wrap (anciennement word-wrap) */
.ew-normal { overflow-wrap: normal; } /* Pas de césure */
.ew-break { overflow-wrap: break-word; } /* Césure si nécessaire */
.ew-anywhere { overflow-wrap: anywhere; } /* Césure partout */
/* word-break */
.wb-normal { word-break: normal; } /* Règles du navigateur */
.wb-all { word-break: break-all; } /* Césure partout (y compris mots) */
.wb-keep { word-break: keep-all; } /* Pas de césure dans les mots */
Comparaison : overflow-wrap vs word-break
lang dans le HTML.
<html lang="fr"> <!-- Nécessaire pour la césure -->
.hyphens-auto {
hyphens: auto; /* Césure automatique selon la langue */
}
.hyphens-manual {
hyphens: manual; /* Césure uniquement aux endroits marqués avec ­ */
}
.hyphens-none {
hyphens: none; /* Pas de césure */
}
/* Insérer un point de césure manuel */
<p>Unmot­long</p>
/* Propriété raccourcie */
.souligne { text-decoration: underline; }
.barre { text-decoration: line-through; }
.suscrit { text-decoration: overline; }
.aucun { text-decoration: none; }
/* Avec style et couleur */
.personnalise {
text-decoration: underline wavy #dc2626;
}
/* Sous-propriétés détaillées */
.deco {
text-decoration-line: underline;
text-decoration-style: dotted;
text-decoration-color: #7c3aed;
text-decoration-thickness: 3px;
text-underline-offset: 4px;
}
| Sous-propriété | Valeurs |
|---|---|
text-decoration-line |
none, underline, overline, line-through, combinables |
text-decoration-style |
solid, dashed, dotted, double, wavy |
text-decoration-color |
Toute valeur de couleur CSS |
text-decoration-thickness |
auto, from-font, ou une valeur de longueur |
text-underline-offset |
auto, ou une valeur de longueur |
Démonstration : text-decoration
text-decoration: underline
text-decoration: line-through
text-decoration: overline
text-decoration: underline wavy #7c3aed
text-decoration: underline thick dotted #dc2626
overflow: hidden et white-space: nowrap.
.ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.clip {
white-space: nowrap;
overflow: hidden;
text-overflow: clip;
}
Démonstration : text-overflow
.retrait {
text-indent: 2em; /* Retrait de 2em */
}
.retrait-negatif {
text-indent: -2em; /* Dépasse à gauche (utile avec padding-left) */
}
.retrait-pourcentage {
text-indent: 10%; /* 10% de la largeur du conteneur */
}
/* Valeurs en longueur */
span { vertical-align: 10px; } /* Décalage vers le haut */
/* Valeurs en pourcentage */
span { vertical-align: -50%; } /* Relatif à la ligne de base */
/* Mots-clés */
sub { vertical-align: sub; } /* Aligné en indice */
sup { vertical-align: super; } /* Aligné en exposant */
.top { vertical-align: top; } /* Haut du conteneur */
.bottom { vertical-align: bottom; } /* Bas du conteneur */
.mid { vertical-align: middle; } /* Milieu de l'x-height */
.baseline { vertical-align: baseline; } /* Défaut : ligne de base */
.text-top { vertical-align: text-top; }
.text-bottom { vertical-align: text-bottom; }
Démonstration : vertical-align
/* Texte de droite à gauche (arabe, hébreu) */
.rtl {
direction: rtl;
unicode-bidi: bidi-override;
}
/* Texte de gauche à droite (défaut) */
.ltr {
direction: ltr;
unicode-bidi: normal;
}
/* Mots-clés pour unicode-bidi */
/* normal — comportement par défaut */
/* embed — imbrique le texte dans une direction */
/* isolate — isole le contenu d'une direction différente */
/* bidi-override — force la direction même pour les chiffres */
/* isolate-override — combine isolate et bidi-override */
┌─────────────────────────────────────────────────────────┐ │ PROPRIÉTÉS TYPOGRAPHIQUES │ ├──────────────────────────┬──────────────────────────────┤ │ FONT (Police) │ TEXT (Texte) │ ├──────────────────────────┼──────────────────────────────┤ │ font-family │ line-height │ │ font-size │ letter-spacing │ │ font-weight │ word-spacing │ │ font-style │ text-align │ │ font-variant │ text-transform │ │ font-stretch │ text-shadow │ │ font-display │ white-space │ │ font (shorthand) │ overflow-wrap │ │ @font-face │ word-break │ │ Google Fonts │ hyphens │ │ Variable fonts │ text-decoration │ │ │ text-overflow │ │ │ text-indent │ │ │ vertical-align │ │ │ direction / unicode-bidi │ └──────────────────────────┴──────────────────────────────┘
Vue d'ensemble de toutes les propriétés typographiques CSS
ÉCHELLE TYPOGRAPHIQUE (ratio 1.25 — Major Third) ──────────────────────────────────────────────── h1 │ 2.441rem │ 39.06px │ Titre principal h2 │ 1.953rem │ 31.25px │ Titre de section h3 │ 1.563rem │ 25.00px │ Sous-titre h4 │ 1.250rem │ 20.00px │ Titre mineur p │ 1.000rem │ 16.00px │ Texte de corps small │ 0.800rem │ 12.80px │ Texte secondaire
Exemple d'échelle typographique harmonieuse basée sur une ratio mathématique
Système d'échelle responsive avec clamp()
/* Échelle basée sur une ratio de 1.25 (Major Third) */
:root {
--step--1: clamp(0.80rem, 0.77rem + 0.15vw, 0.89rem);
--step-0: clamp(1.00rem, 0.96rem + 0.19vw, 1.13rem);
--step-1: clamp(1.25rem, 1.19rem + 0.30vw, 1.41rem);
--step-2: clamp(1.56rem, 1.48rem + 0.41vw, 1.76rem);
--step-3: clamp(1.95rem, 1.84rem + 0.57vw, 2.20rem);
--step-4: clamp(2.44rem, 2.30rem + 0.71vw, 2.75rem);
--step-5: clamp(3.05rem, 2.87rem + 0.91vw, 3.43rem);
}
/* Utilisation */
h1 { font-size: var(--step-5); }
h2 { font-size: var(--step-4); }
h3 { font-size: var(--step-3); }
h4 { font-size: var(--step-2); }
p { font-size: var(--step-0); }
small { font-size: var(--step--1); }
Texte de corps — clamp()
Texte petit — clamp()Styles de paragraphe optimisés pour la lisibilité
.paragraphe-lisible {
font-family: 'Georgia', 'Times New Roman', serif;
font-size: 1.125rem; /* 18px — confortable pour la lecture */
line-height: 1.7; /* Interligne généreux */
letter-spacing: 0.01em; /* Légèrement plus aéré */
color: #1e293b; /* Pas de noir pur — plus doux */
max-width: 65ch; /* ~65 caractères par ligne — optimal */
text-align: justify;
hyphens: auto;
margin-bottom: 1.5em;
}
.paragraphe-lisible + .paragraphe-lisible {
text-indent: 2em; /* Retrait pour indiquer la continuité */
margin-top: 0;
}
La typographie est l'art et la technique de disposer le texte pour le rendre lisible, lisible et attrayant. La disposition du texte est un élément essentiel du design web, car elle influence directement la façon dont les utilisateurs perçoivent et interagissent avec le contenu.
Une bonne typographie ne se limite pas au choix de la police. Elle englobe l'espacement, la hiérarchie, la lisibilité et l'harmonie visuelle. C'est un équilibre subtil entre esthétique et fonctionnalité.
Configuration complète pour un projet
/* === RESET TYPOGRAPHIQUE === */
body {
font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
font-size: clamp(1rem, 0.96rem + 0.19vw, 1.13rem);
line-height: 1.6;
color: #1e293b;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* === TITRES === */
h1, h2, h3, h4, h5, h6 {
font-family: 'Playfair Display', Georgia, serif;
line-height: 1.2;
color: #0f172a;
text-wrap: balance; /* Empêche les orphelins */
}
h1 { font-size: var(--step-5); font-weight: 700; }
h2 { font-size: var(--step-4); font-weight: 700; }
h3 { font-size: var(--step-3); font-weight: 600; }
/* === TEXTE COURANT === */
p {
max-width: 65ch;
text-wrap: pretty; /* Améliore les retours à la ligne */
}
/* === LIENS === */
a {
color: #2563eb;
text-decoration-color: #93c5fd;
text-underline-offset: 3px;
transition: text-decoration-color 0.2s;
}
a:hover {
text-decoration-color: #2563eb;
}
/* === LISTES === */
ul, ol {
padding-left: 1.5em;
}
li {
margin-bottom: 0.4em;
}
/* === CODE === */
code {
font-family: 'Fira Code', 'Cascadia Code', monospace;
font-size: 0.9em;
}
/* === TEXTE SECONDAIRE === */
.texte-clair {
color: #64748b;
font-size: 0.875rem;
}
Font sizing responsive sans media queries
/* clamp(min, preferred, max) */
/* min: taille minimale sur mobile */
/* preferred: taille flexible (vw = viewport width) */
/* max: taille maximale sur desktop */
.titre-principal {
/* De 2rem (mobile) à 4rem (desktop) */
font-size: clamp(2rem, 1.5rem + 2.5vw, 4rem);
}
.sous-titre {
/* De 1.25rem (mobile) à 2rem (desktop) */
font-size: clamp(1.25rem, 1.1rem + 0.75vw, 2rem);
}
.texte-corps {
/* De 1rem (mobile) à 1.125rem (desktop) */
font-size: clamp(1rem, 0.96rem + 0.19vw, 1.125rem);
}
.texte-petit {
/* De 0.75rem (mobile) à 0.875rem (desktop) */
font-size: clamp(0.75rem, 0.72rem + 0.15vw, 0.875rem);
}
/* === OU AVEC DES VARIABLES CSS === */
:root {
--fs-xs: clamp(0.70rem, 0.66rem + 0.18vw, 0.80rem);
--fs-sm: clamp(0.80rem, 0.77rem + 0.15vw, 0.89rem);
--fs-base: clamp(1.00rem, 0.96rem + 0.19vw, 1.13rem);
--fs-md: clamp(1.25rem, 1.19rem + 0.30vw, 1.41rem);
--fs-lg: clamp(1.56rem, 1.48rem + 0.41vw, 1.76rem);
--fs-xl: clamp(1.95rem, 1.84rem + 0.57vw, 2.20rem);
--fs-2xl: clamp(2.44rem, 2.30rem + 0.71vw, 2.75rem);
--fs-3xl: clamp(3.05rem, 2.87rem + 0.91vw, 3.43rem);
}
/* Formule : (min - max) / (vw_min - vw_max) = pente
Preferred = min + pente × (100vw - vw_min) */
/* Utilisation de每体の CSS */
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
body { font-size: var(--fs-base); }
/* FAUX — pas de mise à l'échelle */
body { font-size: 16px; }
h1 { font-size: 32px; }
h2 { font-size: 24px; }
/* CORRECT — utiliser rem et des variables */
:root {
--fs-base: 1rem;
--fs-h1: 2rem;
--fs-h2: 1.5rem;
}
body { font-size: var(--fs-base); }
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
/* FAUX — utiliser italic quand la police le supporte */
.oblique { font-style: oblique; }
/* CORRECT — le vrai italique est plus esthétique */
.italique { font-style: italic; }
/* FAUX — risque de FOIT (Flash of Invisible Text) */
@font-face {
font-family: 'MaPolice';
src: url('mapolice.woff2');
}
/* CORRECT — toujours spécifier font-display */
@font-face {
font-family: 'MaPolice';
src: url('mapolice.woff2') format('woff2');
font-display: swap;
}
/* FAUX — risque de cumul dans les éléments imbriqués */
.parent { line-height: 1.6em; }
.parent .enfant { font-size: 0.875rem; }
/* L'enfant hérite de 1.6em × 16px du parent, pas × sa propre taille */
/* CORRECT — valeur sans unité = multiplicateur */
.parent { line-height: 1.6; }
.parent .enfant { font-size: 0.875rem; }
/* L'enfant hérite du facteur 1.6 × sa propre taille calculée */
/* FAUX — plus de 3 polices = chaos visuel */
body { font-family: 'Arial', sans-serif; }
h1 { font-family: 'Playfair Display', serif; }
h2 { font-family: 'Montserrat', sans-serif; }
h3 { font-family: 'Roboto', sans-serif; }
blockquote { font-family: 'Lora', serif; }
code { font-family: 'Source Code Pro', monospace; }
/* CORRECT — 2 à 3 polices maximum */
body { font-family: 'Inter', sans-serif; }
h1, h2, h3 { font-family: 'Playfair Display', serif; }
code { font-family: 'Fira Code', monospace; }
/* FAUX — crée des rivières de blanc sur écran */
p { text-align: justify; }
/* CORRECT — aligner à gauche pour le texte courant */
p { text-align: left; }
/* Ou utiliser text-align: start pour le RTL support */
<!-- FAUX — charge 10 fichiers de police -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<!-- CORRECT — charge uniquement les graisses utilisées -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
| Bonnes pratiques | Pourquoi |
|---|---|
rem pour les tailles |
Respecte les préférences utilisateur, accessible |
line-height sans unité |
Pas de cumul dans l'imbrication |
max-width: 65ch |
~65 caractères = lisibilité optimale |
clamp() |
Responsive sans media queries |
font-display: swap |
Pas de flash invisible |
text-wrap: balance |
Titres harmonieux |
| Max 3 polices | Cohérence visuelle |
-webkit-font-smoothing |
Rendu net sur macOS/iOS |
Exercice 1 : Font properties
Écris les règles CSS pour :
'Georgia', serif, taille 1.125rem, graisse 300, style italic'Segoe UI', sans-serif, taille 2.5rem, graisse 800, petites capitalesSolution :
.paragraphe {
font-family: 'Georgia', serif;
font-size: 1.125rem;
font-weight: 300;
font-style: italic;
}
.titre {
font-family: 'Segoe UI', sans-serif;
font-size: 2.5rem;
font-weight: 800;
font-variant: small-caps;
}
Exercice 2 : Text properties
Écris les règles CSS pour :
1.8, espacement lettres 0.02em, aligné à gauche, pas de soulignement0.1em, ombre portée simpleSolution :
.texte {
line-height: 1.8;
letter-spacing: 0.02em;
text-align: left;
text-decoration: none;
}
.titre-maj {
text-transform: uppercase;
letter-spacing: 0.1em;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}
Exercice 3 : @font-face
Écris la déclaration @font-face complète pour une police nommée 'MonTitre' :
fonts/h1Solution :
@font-face {
font-family: 'MonTitre';
src: url('fonts/mon-titre.woff2') format('woff2'),
url('fonts/mon-titre.woff') format('woff');
font-weight: 700;
font-display: swap;
}
h1 {
font-family: 'MonTitre', sans-serif;
font-weight: 700;
}
Exercice 4 : Responsive sizing
Crée un système de font-size responsive avec clamp() :
--fs-base : de 1rem à 1.125rem--fs-h1 : de 2rem à 3.5rem--fs-small : de 0.75rem à 0.875remSolution :
:root {
--fs-small: clamp(0.75rem, 0.72rem + 0.15vw, 0.875rem);
--fs-base: clamp(1rem, 0.96rem + 0.19vw, 1.125rem);
--fs-h1: clamp(2rem, 1.75rem + 1.25vw, 3.5rem);
}
body { font-size: var(--fs-base); }
h1 { font-size: var(--fs-h1); }
small { font-size: var(--fs-small); }
Exercice 5 : text-overflow
Crée un conteneur avec du texte tronqué et des points de suspension :
250px)Solution :
.tronque {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Projet : Système typographique complet
Crée un fichier index.html et typographie.css qui démontrent un système typographique complet :
HTML requis :
<h1>, un <h2>, un <h3>.paragraphe<code><blockquote><a><ul><small><p class="majuscules">CSS requis :
--fs-* et clamp()@font-face ou Google Fonts pour 2 policesline-height différent pour titres (1.2), texte (1.7), code (1.5)letter-spacing sur les titres en majusculestext-decoration personnalisé sur les lienstext-shadow sur le titre principalmax-width: 65ch sur les paragraphestext-indent sur le second paragraphewhite-space: pre sur le bloc de codeObjectif : Créer un système typographique cohérent et accessible qui fonctionne sur toutes les tailles d'écran.
Quiz rapide
font-style: italic et font-style: oblique ?line-height sans unité plutôt qu'avec em ?font-display ?text-shadow ?max-width: 65ch est important pour la lisibilité ?text-wrap: balance fait sur un titre ?italic utilise une forme dessinée spécialement par le typographe ; oblique penche simplement les caractères normaux.swap — affiche le fallback immédiatement, remplace quand la police est prête.text-overflow: ellipsis (avec overflow: hidden et white-space: nowrap).text-shadow: offsetX offsetY blur-radius color;text-transform: uppercasetext-wrap: balance répartit les mots sur les lignes pour éviter les orphelins (mot seul sur la dernière ligne).