La propriété hyphens indique au navigateur comment gérer les traits d'union lors des sauts de ligne. Grâce à elle, on peut empêcher l'utilisation des traits d'union en fin de ligne, contrôler quand ils sont ajoutés ou laisser le navigateur décider.
Le code source de cet exemple interactif est disponible dans un dépôt GitHub. Si vous souhaitez contribuez à ces exemples, n'hésitez pas à cloner https://github.com/mdn/interactive-examples et à envoyer une pull request !
Les règles relatives aux traits d'union en fin de ligne dépendent de la langue utilisée. En HTML, la langue est définie grâce à l'attribut lang et les navigateurs n'appliqueront les règles que si cet attribut est présent et que le dictionnaire correspondant (pour la gestion des traits d'union et des fins de ligne) est disponible. Pour des documents XML, on utilisera l'attribut xml:lang.
Syntaxe
/* Valeurs avec un mot-clé */ hyphens: none; hyphens: manual; hyphens: auto; /* Valeurs globales */ hyphens: inherit; hyphens: initial; hyphens: unset;
Valeurs
none- Les mots ne sont pas coupés en fin de ligne et ce même si les caractères invitent à une coupe. Les lignes se termineront uniquement sur des blancs.
manual- Les mots sont coupés là où des caractères invitant à un saut de ligne sont présents. Voir la section suivante pour plus de détails.
auto- Le navigateur est libre de couper les mots là où il l'estime approprié selon les règles qu'il choisit. Les emplacements de coupe suggérés par certains caractères devraient être privilégiés par rapport aux coupes automatiques.
auto dépend de la langue indiquée par le document. Aussi, il faut indiquer la langue via l'attribut HTML lang pour s'assurer que les fins de ligne et les traits d'union sont bien gérés selon la langue indiquée.Syntaxe formelle
none | manual | auto
Suggérer des emplacements de coupe pour les lignes
Deux caractères Unicode peuvent être utilisés manuellement pour indiquer des emplacement où effectuer des sauts de ligne :
- U+2010 (HYPHEN)
- Un trait d'union « dur » qui indique un emplacement indiqué pour un saut de ligne. Même si la ligne n'est pas coupée à cet endroit, le trait d'union est affiché.
- U+00AD (SOFT HYPHEN)
- Un trait d'union « doux ». Ce caractère n'est pas affichée de façon visible. Il indique au navigateur un emplacement où effectuer le saut de ligne si nécessaire. En HTML, on peut utiliser l'entité
­pour insérer ce caractère.
Exemples
Dans cet exemple, on crée trois classes CSS pour illustrer chacune des configurations possibles pour la propriété hyphens.
CSS
p {
width: 55px;
border: 1px solid black;
}
p.none {
-webkit-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
p.manual {
-webkit-hyphens: manual;
-ms-hyphens: manual;
hyphens: manual;
}
p.auto {
-webkit-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;
}
HTML
<ul>
<li><code>none</code>: aucun trait d'union, dépassement si nécessaire
<p lang="en" class="none">An extreme­ly long English word</p>
</li>
<li><code>manual</code>: un trait d'union uniquement à &hyphen; ou &shy; (si nécessaire)
<p lang="en" class="manual">An extreme­ly long English word</p>
</li>
<li><code>auto</code>: un trait d'union où l'algorithme l'estime nécessaire
<p lang="en" class="auto">An extreme­ly long English word</p>
</li>
</ul>
Résultat
Spécifications
| Spécification | État | Commentaires |
|---|---|---|
| CSS Text Module Level 3 La définition de 'hyphens' dans cette spécification. |
Version de travail | Définition initiale. |
| Valeur initiale | manual |
|---|---|
| Applicabilité | tous les éléments |
| Héritée | oui |
| Média | visuel |
| Valeur calculée | comme spécifié |
| Type d'animation | discrète |
| Ordre canonique | l'ordre unique et non-ambigu défini par la grammaire formelle |
Compatibilité des navigateurs
| Fonctionnalité | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Support simple | 55 | ? | 43 | 10 -ms- 3 | 44 | 5.1 -webkit- |
| Hyphenation dictionary for Afrikaans (af, af-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Bosnian, Serbian, and Serbo-Croatian (sh, sh-*, sr, sr-*, bs, bs-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Bulgarian (bg, bg-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Catalan (ca, ca-*) | ? | ? | 8 | 10 | ? | 5.1 |
| Hyphenation dictionary for Croatian (hr, hr-*) | ? | ? | 8 | 10 | ? | 9.1 |
| Hyphenation dictionary for Czech (cs, cs-*) | ? | ? | Non | 10 | ? | 9.1 |
| Hyphenation dictionary for Esperanto (eo, eo-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Estonian (et, et-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Danish (da, da-*) | ? | ? | 8 | 10 | ? | 5.1 |
| Hyphenation dictionary for Dutch (nl, nl-*) | ? | ? | 8 | 10 | ? | 5.1 |
| Hyphenation dictionary for Finnish (fi, fi-*) | ? | ? | 8 | 10 | ? | 9.1 |
| Hyphenation dictionary for French (fr, fr-*) | ? | ? | 8 | 10 | ? | 5.1 |
| Hyphenation dictionary for Galician (gl, gl-*) | ? | ? | 9 | Non | ? | Non |
| Hyphenation dictionary for German, Reformed Orthography of 1996 (de, de-1996, de-DE, de-AT, de-*) | ? | ? | 8 | 10 | ? | 5.1 |
| Hyphenation dictionary for German, Traditional Orthography of 1901 (de-1901, de-AT-1901, de-DE-1901) | ? | ? | 8 | ? | ? | ? |
| Hyphenation dictionary for German, Swiss Orthography (de-CH, de-CH-*) | ? | ? | 8 | ? | ? | ? |
| Hyphenation dictionary for Hungarian (hu, hu-*) | ? | ? | 9 | Non | ? | 9.1 |
| Hyphenation dictionary for Icelandic (is, is-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Interlingua (ia, ia-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Italian (it, it-*) | ? | ? | 9 | 10 | ? | 5.1 |
| Hyphenation dictionary for Kurmanji (kmr, kmr-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Latin (la, la-*) | Oui | ? | 8 | Non | 44 | Non |
| Hyphenation dictionary for Lithuanian (lt, lt-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Mongolian (mn, mn-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Norwegian (Bokmål) (no, no-*, nb, nb-*) | ? | ? | 8 | 10 | ? | 5.1 |
| Hyphenation dictionary for Norwegian (Nynorsk) (nn, nn-*) | ? | ? | 8 | 10 | ? | Non |
| Hyphenation dictionary for Polish (pl, pl-*) | ? | ? | 31 | 10 | ? | 9.1 |
| Hyphenation dictionary for Portuguese (pt, pt-*) | ? | ? | 8 | 10 | ? | 9.1 |
| Hyphenation dictionary for Brazilian Portuguese (pt-BR) | ? | ? | 84 | 10 | ? | Non |
| Hyphenation dictionary for Russian (ru, ru-*) | ? | ? | 8 | 10 | ? | 5.1 |
| Hyphenation dictionary for Slovenian (sl, sl-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Spanish (es, es-*) | ? | ? | 8 | 10 | ? | 5.1 |
| Hyphenation dictionary for Swedish (sv, sv-*) | ? | ? | 8 | 10 | ? | 5.1 |
| Hyphenation dictionary for Turkish (tr, tr-*) | ? | ? | 9 | 10 | ? | 5.1 |
| Hyphenation dictionary for Ukrainian (uk, uk-*) | ? | ? | 9 | Non | ? | 9.1 |
| Hyphenation dictionary for Upper Sorbian (hsb, hsb-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for Welsh (cy, cy-*) | ? | ? | 8 | Non | ? | Non |
| Hyphenation dictionary for English (en, en-*) | 55 | ? | 65 | 10 | 44 | 5.16 |
| Fonctionnalité | Android webview | Chrome for Android | Edge mobile | Firefox for Android | Opera Android | iOS Safari | Samsung Internet |
|---|---|---|---|---|---|---|---|
| Support simple | 55 4 -webkit- | 55 | ? | 43 | 44 | 4.2 -webkit- | 6.0 |
| Hyphenation dictionary for Afrikaans (af, af-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Bosnian, Serbian, and Serbo-Croatian (sh, sh-*, sr, sr-*, bs, bs-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Bulgarian (bg, bg-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Catalan (ca, ca-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Croatian (hr, hr-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Czech (cs, cs-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Esperanto (eo, eo-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Estonian (et, et-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Danish (da, da-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Dutch (nl, nl-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Finnish (fi, fi-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for French (fr, fr-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Galician (gl, gl-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for German, Reformed Orthography of 1996 (de, de-1996, de-DE, de-AT, de-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for German, Traditional Orthography of 1901 (de-1901, de-AT-1901, de-DE-1901) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for German, Swiss Orthography (de-CH, de-CH-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Hungarian (hu, hu-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Icelandic (is, is-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Interlingua (ia, ia-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Italian (it, it-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Kurmanji (kmr, kmr-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Latin (la, la-*) | Oui | Oui | ? | ? | 44 | ? | Oui |
| Hyphenation dictionary for Lithuanian (lt, lt-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Mongolian (mn, mn-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Norwegian (Bokmål) (no, no-*, nb, nb-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Norwegian (Nynorsk) (nn, nn-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Polish (pl, pl-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Portuguese (pt, pt-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Brazilian Portuguese (pt-BR) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Russian (ru, ru-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Slovenian (sl, sl-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Spanish (es, es-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Swedish (sv, sv-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Turkish (tr, tr-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Ukrainian (uk, uk-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Upper Sorbian (hsb, hsb-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for Welsh (cy, cy-*) | ? | ? | ? | ? | ? | ? | ? |
| Hyphenation dictionary for English (en, en-*) | 55 | 55 | ? | ? | 44 | ? | 6.0 |
1. Only -webkit-hyphens: none is supported.
2. Automatic hyphenation only works for languages with hyphenation dictionaries that are integrated into Firefox.
3. Automatic hyphenation only works for languages with hyphenation dictionaries that are integrated into Internet Explorer.
4. For Brazilian Portuguese, Firefox uses a Portuguese dictionary.
5. For English, Firefox uses an en-US dictionary
6. For English, Safari uses different en-GB and en-US dictionaries.