Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / HTML

concetto HTML: typography

HTML descrive il significato dei frammenti testuali; carattere, dimensione, peso e spaziatura spettano a CSS.

Versione: WHATWG HTML Living Standard; index snapshot date recorded separately

Sintassi

semantic inline elements + CSS presentation

em indica enfasi che cambia il senso, strong importanza, serietà o urgenza; non sono comandi intercambiabili di corsivo e grassetto.

b, i, u e mark hanno significati propri e ristretti; usali per il contesto, non solo per l’aspetto.

sub e sup servono convenzioni di notazione, non testo minore; br inserisce una rottura del contenuto, non spazio tra paragrafi.

L’esempio mantiene nodi em, strong, sub, sup e br separati, sebbene textContent unisca il testo visibile.

Esempi

<!doctype html>
<meta charset="utf-8">
<p id="statement">You <em>must</em> save. <strong>Warning</strong>: H<sub>2</sub>O, x<sup>2</sup>.<br>Next line.</p>
<output id="result"></output>
<script>
const statement = document.querySelector("#statement");
result.textContent = `em=${statement.querySelector("em").textContent}; strong=${statement.querySelector("strong").textContent}; sub=${statement.querySelector("sub").textContent}; sup=${statement.querySelector("sup").textContent}; breaks=${statement.querySelectorAll("br").length}; text=${statement.textContent}`;
</script>

Risultato

em=must; strong=Warning; sub=2; sup=2; breaks=1; text=You must save. Warning: H2O, x2.Next line.

Il risultato conferma la struttura DOM; non prova font, impaginazione delle righe o pronuncia assistita.

Fonti