Quote and Apostrophe HTML Entities Explained
- Quotes inside attribute values must be encoded to avoid breaking the attribute
- " encodes double quotes, ' encodes apostrophes/single quotes
- Apostrophes in attribute values are safe when the attribute uses double quotes — encoding is optional but safe
- Free encoder handles both automatically alongside all other reserved characters
Table of Contents
Quotes are special in HTML for one main reason: attributes are wrapped in them. An unencoded quote inside an attribute value closes the attribute early and breaks the markup. The character after it becomes part of the tag syntax rather than the attribute content — a source of confusing bugs and security issues.
" and ' are the entities that solve this.
Why Unencoded Quotes Break HTML Attributes
Consider this example. You want a title attribute with a double quote in it:
Wrong: <abbr title="The "best" solution">
The parser sees the second double quote as the end of the attribute value. "best" and the rest become unexpected content inside the opening tag — the markup is broken.
Correct: <abbr title="The "best" solution">
The entity " is not treated as an attribute delimiter. The attribute value is read correctly and the rendered title shows the actual quote characters.
The same logic applies to single quotes in attributes that use single-quote delimiters: <a title='It's working'>
" and ': When to Use Each
| Character | Entity | When Required |
|---|---|---|
| " | " | Inside double-quoted attribute values. Optional in body text. |
| ' | ' | Inside single-quoted attribute values. Optional elsewhere. |
The shortcut rule: encode the quote type that matches your attribute delimiter. If your attribute uses double quotes, encode any literal double quotes inside the value as ". Single quotes inside a double-quoted attribute are safe without encoding.
Note: ' is defined in HTML5 and XML but was not part of the original HTML4 specification. If you need broad compatibility with very old parsers, use the numeric entity ' instead of '.
Sell Custom Apparel — We Handle Printing & Free ShippingApostrophes in Body Text: Do You Need to Encode Them?
No — apostrophes and single quotes in HTML body text do not need to be encoded. They have no special meaning outside of attribute delimiters.
You can write "it's" and "don't" directly in your HTML body without any encoding. The browser renders them as literal characters.
The only time to encode an apostrophe is when it appears inside a single-quoted HTML attribute value — which is uncommon since most HTML uses double quotes for attributes.
Curly/smart quotes (the typographic " " and ' ') are also fine in UTF-8 HTML without encoding. They are completely different code points from the straight ASCII quote characters and have no special meaning in HTML syntax.
Quotes in data- Attributes and Inline JavaScript
A common pattern that requires careful quote handling: data attributes and inline event handlers that contain string values.
data- attributes with string values:<div data-label="Tom & Jerry "Classic"">
Both & and " inside the attribute value need encoding.
Inline JavaScript with string arguments (generally avoid this pattern):
The safest approach is to store values in data- attributes and read them with JavaScript rather than embedding string literals in onclick handlers. If you must use inline handlers, encoding quotes becomes complex because you have both HTML and JavaScript contexts layered together — a recipe for bugs and potential XSS vulnerabilities.
The general recommendation: use data- attributes for passing values to JavaScript, and handle click events in a script tag rather than inline attributes. This avoids the quote escaping problem entirely.
Encode Quotes and All Special Characters
Paste your content. " ' and all entities handled. Free, no signup.
Open Free HTML Entity ToolFrequently Asked Questions
What is the HTML entity for a double quote?
" is the named entity for ". The numeric equivalent is ". Use it inside double-quoted attribute values where a literal " would close the attribute.
What is the HTML entity for an apostrophe?
' is the HTML5 entity for '. The numeric equivalent ' has wider legacy support. Only required inside single-quoted attribute values.
Do I need to encode apostrophes in HTML body text?
No. Apostrophes in body text have no special HTML meaning and do not need encoding. Write them directly.
What happens if I put an unencoded quote inside an attribute value?
The parser treats it as the end of the attribute value. Everything after the unencoded quote is interpreted as tag content rather than attribute data — breaking the markup.

