Stax
Tools

HTML Entity Encoder / Decoder

Encode HTML special characters to entities or decode entities.

Common HTML entities reference
CharEntityCharEntity
&&amp;<&lt;
>&gt;"&quot;
'&#39; &nbsp;
©&copy;®&reg;
&trade;&euro;
£&pound;¥&yen;
¢&cent;§&sect;
°&deg;±&plusmn;
×&times;÷&divide;
¼&frac14;½&frac12;
¾&frac34;&ndash;
&mdash;&lsquo;
&rsquo;&ldquo;
&rdquo;&bull;
&hellip;&larr;
&rarr;&uarr;
&darr;&harr;
&spades;&clubs;
&hearts;&diams;

常にエンコードすべき5つの重要なHTML文字

3つのエンコードモードの解説

HTMLエンティティのデコード

HTMLコンテンツとしてレンダリングされるテキストは、解析の問題とXSS攻撃を防ぐためにこれらの5つの文字をエスケープする必要があります:

デコードモードに切り替えると、HTMLエンティティを読みやすい文字に変換できます。HTMLのソースコードを読む、エンコードされたメールの本文を確認する、APIからのHTMLエンコードデータを処理する際に便利です。

バックエンド開発者はXSSの脆弱性を防ぐためにHTMLテンプレートに書き込む前にユーザー送信フォームデータをサニタイズするためにエンコーダーを使用します。コンテンツチームはブログ下書きを貼り付け、公開前にemダッシュや著作権記号などの特殊文字を名前付きエンティティにエンコードします。フロントエンドエンジニアはHTMLエスケープされた文字列を返すAPIレスポンスを読むためにデコードモードを使用し、メール開発者はエンコードの処理が不統一なメールクライアント全体で正しいレンダリングを保証するためにコンテンツをエンコードします。

  • & (アンパサンド) → &amp;
  • < (小なり) → &lt;
  • > (大なり) → &gt;
  • " (ダブルクォート) → &quot;
  • ' (シングルクォート) → &#39;
  • 最小限:上記の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 (&amp;) and end with a semicolon (;). For example, &lt; represents < (which would otherwise start an HTML tag) and &amp; represents &amp; (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 < > &amp; " ' 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: &lt; for <, &amp;copy; for ©. Numeric entities use the character's decimal (&#60;) or hex (&amp;#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 &lt; and &gt; 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: &amp; (→ &amp;), < (→ &lt;), > (→ &gt;), " (→ &quot;), and ' (→ &#39;). 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.

関連ツール