HTML Entity Encoder / Decoder
Encode HTML special characters to entities or decode entities.
Common HTML entities reference
| Char | Entity | Char | Entity |
|---|---|---|---|
| & | & | < | < |
| > | > | " | " |
| ' | ' | | |
| © | © | ® | ® |
| ™ | ™ | € | € |
| £ | £ | ¥ | ¥ |
| ¢ | ¢ | § | § |
| ° | ° | ± | ± |
| × | × | ÷ | ÷ |
| ¼ | ¼ | ½ | ½ |
| ¾ | ¾ | – | – |
| — | — | ‘ | ‘ |
| ’ | ’ | “ | “ |
| ” | ” | • | • |
| … | … | ← | ← |
| → | → | ↑ | ↑ |
| ↓ | ↓ | ↔ | ↔ |
| ♠ | ♠ | ♣ | ♣ |
| ♥ | ♥ | ♦ | ♦ |
常にエンコードすべき5つの重要なHTML文字
3つのエンコードモードの解説
HTMLエンティティのデコード
HTMLコンテンツとしてレンダリングされるテキストは、解析の問題とXSS攻撃を防ぐためにこれらの5つの文字をエスケープする必要があります:
デコードモードに切り替えると、HTMLエンティティを読みやすい文字に変換できます。HTMLのソースコードを読む、エンコードされたメールの本文を確認する、APIからのHTMLエンコードデータを処理する際に便利です。
バックエンド開発者はXSSの脆弱性を防ぐためにHTMLテンプレートに書き込む前にユーザー送信フォームデータをサニタイズするためにエンコーダーを使用します。コンテンツチームはブログ下書きを貼り付け、公開前にemダッシュや著作権記号などの特殊文字を名前付きエンティティにエンコードします。フロントエンドエンジニアはHTMLエスケープされた文字列を返すAPIレスポンスを読むためにデコードモードを使用し、メール開発者はエンコードの処理が不統一なメールクライアント全体で正しいレンダリングを保証するためにコンテンツをエンコードします。
- & (アンパサンド) → &
- < (小なり) → <
- > (大なり) → >
- " (ダブルクォート) → "
- ' (シングルクォート) → '
- 最小限:上記の5つのHTML特殊文字のみをエンコードします。HTMLでユーザーコンテンツをレンダリングしてXSSを防ぐ際に使用します。
- 名前付きエンティティ:名前付き文字(©・®・€・→など)をHTMLエンティティ相当に変換します。タイポグラフィ的に正しいHTMLに便利です。
- 数値:すべての非ASCII文字を10進数文字参照(&#xx;)としてエンコードします。厳密なASCIIのみのHTMLドキュメントを対象とする場合に使用します。
よくある質問
- What are HTML entities?
- HTML entities are special codes used to represent characters that either have special meaning in HTML or cannot be typed easily. They start with an ampersand (&) and end with a semicolon (;). For example, < represents < (which would otherwise start an HTML tag) and & represents & (which would otherwise start an entity).
- When do I need to encode HTML characters?
- Encode HTML characters when: (1) displaying user-submitted content in HTML to prevent XSS (Cross-Site Scripting) attacks — any < > & " ' must be encoded, (2) including special symbols like copyright ©, registered ®, or currency signs in HTML, (3) placing HTML code examples inside a web page for display.
- What is the difference between named and numeric entities?
- Named entities use a descriptive name: < for <, &copy; for ©. Numeric entities use the character's decimal (<) or hex (&#x3C;) Unicode code point. Named entities are more readable; numeric entities work for any character, even those without a named equivalent. All browsers support both.
- What is XSS and how does encoding prevent it?
- Cross-Site Scripting (XSS) is an attack where malicious JavaScript is injected into a web page via unescaped user input. If a user submits <script>alert(1)</script> and it is rendered as HTML, the script executes. Encoding the < and > as < and > makes the browser display the text literally instead of executing it as HTML.
- What is the minimal encoding level?
- Minimal encoding only escapes the 5 characters with special meaning in HTML: & (→ &), < (→ <), > (→ >), " (→ "), and ' (→ '). This is the minimum required to safely embed text in HTML and prevent XSS. Use this level when you need to display user input in an HTML page.
関連ツール
- JSON Formatter, Validator & Repair Tool
Format, minify, validate, and repair JSON instantly in your browser. Sort keys alphabetically, auto-format on paste, download as file, escape/unescape strings — free, no sign-up, 100% client-side.
- QRコード生成
URL、テキスト、Wi-FiなどのQRコードを生成。PNGでダウンロード可能。
- パスワード生成
カスタム長と文字セットで強力なランダムパスワードを生成。
- Base64 エンコーダー / デコーダー
テキストをBase64にエンコード、または逆にデコード。
- URLエンコーダー / デコーダー
パーセントエンコーディングでURLとクエリ文字列をエンコードまたはデコード。