HTML Entity for Apostrophe (')

Beginner
⏱️ 5 min read
📚 Updated: May 2026
🎯 1 Code Example
Unicode U+0027

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

Unicode U+0027

Basic Latin (ASCII)

Hex Code '

Hexadecimal reference

HTML Code '

Decimal reference

Named Entity '

XML / HTML5

CSS Code \0027

Six-digit escape (safe)

Reference Table
Name           Value
────────────   ──────────
Unicode        U+0027
Hex code       '
HTML code      '
Named entity   '
CSS code       \0027
1

Complete 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:

html
<!DOCTYPE html>
<html>
<head>
 <style>
  #point:after{
   content: "\0027";
  }
 </style>
</head>
<body>

<p>Apostrophe using Hexa Decimal: &#x27;</p>
<p>Apostrophe using HTML Code: &#39;</p>
<p>Apostrophe using HTML Entity: &apos;</p>
<p id="point">Apostrophe using CSS Entity: </p>

</body>
</html>

In the listing above, the named entity is written as &apos; (numeric ampersand + apos;) so it displays as copyable &apos; text without being interpreted by this page’s own parser.

Try It Yourself

🌐 Browser Support

The apostrophe and apos named reference are universal in HTML user agents. Any font that covers Basic Latin will render U+0027:

Chrome 1+
Firefox 1+
Safari 1+
Edge 12+
Opera 4+
Android 4.4+
iOS Safari 1+

👀 Live Preview

See U+0027 in typical text and attribute-style snippets:

Isolated glyph '
In a sentence It's 39° outside — don't forget O'Brien's umbrella.
Named ref Same character as &apos; in UTF-8 HTML.
Monospace U+0027 APOSTROPHE
Typographic note For curly apostrophes in prose, editors often prefer U+2019 (&rsquo; / &#8217;); U+0027 remains the standard for code, ASCII data, and entity tutorials.

🧠 How It Works

1

Named entity

&apos; (ampersand + apos + semicolon) is the standard named form. It is especially readable inside single-quoted attributes.

HTML markup
2

Numeric references

&#39; (decimal) and &#x27; (hex) resolve to the same code point and are widely used in generated markup.

HTML markup
3

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.

CSS stylesheet
4

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.

UTF-8 source
=

Same character

All supported spellings map to U+0027 (APOSTROPHE, Basic Latin). Prefer &apos; or numerics inside single-quoted attributes.

Use Cases

U+0027 shows up everywhere English (and similar) text is encoded in HTML:

📝 Contractions and possessives

can't, it's, users' data — escape inside single-quoted attributes.

🏷 Single-quoted attributes

data-msg='Save user's draft' style patterns in components.

🌐 Names and locales

O'Brien, d'Artagnan, L'Oréal in titles, labels, and CMS fields.

💬 User-generated content

Encode apostrophes when echoing strings into HTML attributes to avoid broken markup.

📄 JSON-in-HTML

When embedding JSON in <script type="application/json"> or data attributes, follow JSON string rules (often \u0027 in JS, not HTML entities).

🔧 Code samples

Show character references in tutorials so readers can copy portable markup.

🔒 Defense in depth

Correct escaping in attributes complements CSP, sanitizers, and templating auto-escape.

💡 Best Practices

Do

  • Use &apos; or &#39; 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 \0027 in CSS content, 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 &apos;
  • Rely on apostrophe escaping alone for XSS protection—use proper sanitization

Key Takeaways

1

Three common HTML spellings for U+0027

&apos; &#39; &#x27;
2

CSS content escape

\0027
3

Unicode U+0027 — APOSTROPHE (Basic Latin)

4

Escape inside single-quoted attributes; double-quoted attributes are usually easier for English prose

5

Curly apostrophes in typography are often U+2019, a different character

❓ Frequently Asked Questions

Use a literal ' in UTF-8 text, or &apos;, &#39;, &#x27;. 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.
Whenever the apostrophe sits inside an attribute value delimited with the same single-quote character—for example title='Don&apos;t'. Otherwise a literal apostrophe is usually acceptable in HTML5 text.
Markup uses &apos;, &#39;, or &#x27; in HTML. CSS uses \0027 (or a shorter escape with a terminator) inside content rules. Same code point; different syntax layer.
Yes. It is one of the five predefined XML entities and is supported in HTML5 for U+0027. It is especially useful for readable, portable escaping.

Explore More HTML Entities!

Discover 1500+ HTML character references — currency symbols, arrows, math operators, emojis, and more.

All HTML Entities →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful