HTML Entity for Apostrophe (')
What You'll Learn
How to type the ASCII apostrophe (U+0027, Unicode name APOSTROPHE) in HTML and when to escape it. This is the straight quote used in contractions and possessives (for example it's, O'Brien) and the same code point often used as a closing single quote in plain ASCII text.
You can write it literally in HTML text, or use ', ', or '. Inside single-quoted attribute values, you must escape it so the parser does not think the attribute ended early—for example title='Don't' (or use double quotes around the attribute value instead).
⚡ Quick Reference — Apostrophe
U+0027Basic Latin (ASCII)
'Hexadecimal reference
'Decimal reference
'XML / HTML5
\0027Six-digit escape (safe)
Name Value
──────────── ──────────
Unicode U+0027
Hex code '
HTML code '
Named entity '
CSS code \0027Complete HTML Example
This example shows U+0027 using hexadecimal code, decimal code, the apos named reference, and a CSS content escape on a pseudo-element:
<!DOCTYPE html>
<html>
<head>
<style>
#point:after{
content: "\0027";
}
</style>
</head>
<body>
<p>Apostrophe using Hexa Decimal: '</p>
<p>Apostrophe using HTML Code: '</p>
<p>Apostrophe using HTML Entity: '</p>
<p id="point">Apostrophe using CSS Entity: </p>
</body>
</html>In the listing above, the named entity is written as ' (numeric ampersand + apos;) so it displays as copyable ' text without being interpreted by this page’s own parser.
🌐 Browser Support
The apostrophe and apos named reference are universal in HTML user agents. Any font that covers Basic Latin will render U+0027:
👀 Live Preview
See U+0027 in typical text and attribute-style snippets:
' in UTF-8 HTML.’); U+0027 remains the standard for code, ASCII data, and entity tutorials.🧠 How It Works
Named entity
' (ampersand + apos + semicolon) is the standard named form. It is especially readable inside single-quoted attributes.
Numeric references
' (decimal) and ' (hex) resolve to the same code point and are widely used in generated markup.
CSS escape
\0027 in content emits U+0027 from a stylesheet. A six-digit escape avoids ambiguity when the next character is a hex digit.
Literal character
In HTML text and in double-quoted attributes, you can often type ' directly (UTF-8). Escaping is still allowed and sometimes preferred for consistency.
Same character
All supported spellings map to U+0027 (APOSTROPHE, Basic Latin). Prefer ' or numerics inside single-quoted attributes.
Use Cases
U+0027 shows up everywhere English (and similar) text is encoded in HTML:
can't, it's, users' data — escape inside single-quoted attributes.
data-msg='Save user's draft' style patterns in components.
O'Brien, d'Artagnan, L'Oréal in titles, labels, and CMS fields.
Encode apostrophes when echoing strings into HTML attributes to avoid broken markup.
When embedding JSON in <script type="application/json"> or data attributes, follow JSON string rules (often \u0027 in JS, not HTML entities).
Show character references in tutorials so readers can copy portable markup.
Correct escaping in attributes complements CSP, sanitizers, and templating auto-escape.
💡 Best Practices
Do
- Use
'or'inside single-quoted attribute values - Prefer double quotes for attributes when the value contains many apostrophes
- Let your template engine or framework escape dynamic strings by default
- Use
\0027in CSScontent, not raw HTML entity syntax - Validate markup after templating changes that touch user-facing strings
Don’t
- Assume a “smart quote” from Word is U+0027 without normalizing
- Mix hand-escaped fragments with unescaped user input in the same attribute
- Paste CSS escapes into HTML text nodes
- Forget that JavaScript strings use
\'or\u0027, not' - Rely on apostrophe escaping alone for XSS protection—use proper sanitization
Key Takeaways
Three common HTML spellings for U+0027
' ' 'CSS content escape
\0027Unicode U+0027 — APOSTROPHE (Basic Latin)
Escape inside single-quoted attributes; double-quoted attributes are usually easier for English prose
Curly apostrophes in typography are often U+2019, a different character
❓ Frequently Asked Questions
' in UTF-8 text, or ', ', '. In CSS content, use \0027. Inside single-quoted attributes, prefer entities or switch to double-quoted attributes.U+0027 (decimal 39, hex 27). Official name: APOSTROPHE. Not the same as U+2019 RIGHT SINGLE QUOTATION MARK used for curly apostrophes in many fonts.title='Don't'. Otherwise a literal apostrophe is usually acceptable in HTML5 text.', ', or ' in HTML. CSS uses \0027 (or a shorter escape with a terminator) inside content rules. Same code point; different syntax layer.Explore More HTML Entities!
Discover 1500+ HTML character references — currency symbols, arrows, math operators, emojis, and more.
8 people found this page helpful
