エンコード
HTML Entities Encode/Decode
HTML エンティティのエンコード・デコード — ページ上で特殊文字を安全に表示。
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.
よくある質問
HTML エンティティとは何ですか?
<や&のようにHTMLで特別な意味を持つ文字や、キーボードで入力しにくい記号を、マークアップを壊さずページに表示するための表記法です。<のような名前付き参照と、<や<のような数値参照の2種類があります。
「基本」と「すべての文字」の違いは何ですか?
「基本」は<、>、&、\"、'などHTMLの構文上エスケープが必須な文字だけを変換します。「すべての文字」はASCII範囲外の文字も含め、対応するエンティティにできる限り変換します。
名前付きエンティティと数値参照はどちらを使うべきですか?
&のような名前付きエンティティは可読性が高く一般的ですが、HTMLが定義する名前付きエンティティは限られています。&や&のような数値参照はどんな文字コードポイントにも使えるため、より汎用的です。
本文中と属性内ではエスケープの仕方が違いますか?
基本的な文字(<、>、&)のエスケープは同じですが、引用符で囲まれた属性の中ではさらに、その属性を囲んでいる引用符の種類を必ずエスケープする必要があります。そうしないと値が想定より早く「断ち切られて」しまいます。
HTMLエスケープはすべての種類のXSSを防げますか?
いいえ。最も一般的な経路であるHTMLコンテンツへのテキスト挿入は防げますが、innerHTMLなどJavaScriptの文脈で発生するXSSや、href/src内の未検証URLによる攻撃は防げません。