Codifica
HTML Entities Encode/Decode
Codifica e decodifica di entità HTML — visualizzazione sicura di caratteri speciali nella pagina.
HTML entities are a way to write characters that would otherwise break markup (<, >, &) or have no keyboard key, as safe text sequences like < or &. This tool encodes and decodes such entities right in your browser.
How to use it
- Encode: paste text and characters like <, >, &, and quotes get replaced with their matching entities.
- Decode: paste HTML containing entities (&, ©, etc.) to see the plain text.
- Both named entities (&) and numeric ones (& or &) are supported.
Common uses
- Safely displaying user text (a comment, a message) on a page without risking broken markup or an injected script.
- Embedding HTML code samples in an article or documentation so the browser shows them as text instead of rendering them.
- Decoding content copied from another site where the characters arrived already entity-encoded.
Things to keep in mind
HTML entity escaping only protects against XSS via a page's text content — it does not protect a JavaScript context (innerHTML, eval) or href/src attributes containing unvalidated URLs.
Encode exactly at the point where text gets inserted into HTML, not ahead of time when saving to a database — otherwise the data gets mangled when reused outside an HTML context.
Articolo su questo strumento: HTML Entities: come mostrare caratteri speciali in sicurezza
Domande frequenti
Qual è la differenza tra entità HTML nominate e numeriche?
Le entità nominate come & sono più facili da leggere, mentre quelle numeriche come & o & (decimale o esadecimale) funzionano per qualsiasi carattere, inclusi quelli privi di entità nominata. Entrambe vengono renderizzate in modo identico nel browser.
Quando devo davvero codificare le entità HTML?
Codifica caratteri come < > & " ' ogni volta che inserisci testo dinamico o fornito dall'utente in markup HTML, così il browser li tratta come testo e non come parte di un tag o attributo.
Qual è la differenza tra la modalità "Base" e "Tutti i caratteri"?
La modalità Base esegue l'escape solo dei caratteri strutturalmente significativi in HTML (come < > & " '), mentre "Tutti i caratteri" converte anche altri caratteri non ASCII in entità numeriche, utile per parser più vecchi o rigidi.
Il testo in un attributo va escapato diversamente rispetto al corpo della pagina?
I caratteri principali (<, >, &) si escapano allo stesso modo, ma dentro un attributo tra virgolette è fondamentale escapare anche esattamente il tipo di virgoletta che delimita l'attributo — altrimenti il valore si "romperà" prima del previsto.
L'escaping HTML protegge da tutti i tipi di XSS?
No. Copre il vettore più comune — l'inserimento di testo nel contenuto HTML — ma non protegge dall'XSS tramite contesto JavaScript (ad esempio innerHTML con esecuzione di codice) o da URL non validati in href/src.