How to Write Apostrophe in HTML

Rajeev Baniya Feb 02, 2024
  1. Use the Entity Number ’ or the Entity Name ’ to Write Apostrophe in HTML
  2. Use the Entity Number ' or the Entity Name ' to Write Apostrophe in HTML
How to Write Apostrophe in HTML

This article will introduce methods to write apostrophes in HTML.

Use the Entity Number ’ or the Entity Name ’ to Write Apostrophe in HTML

There are some reserved characters in HTML. The browser may interpret those characters as something else from what we intended, so it is necessary to escape those characters.

For example, when we write the greater than > or less than < symbols, the browser will interpret them as HTML tags. In such a case, we use the entity name or the entity number to escape the character.

Several special characters need to be escaped in HTML. The apostrophe sign is one of them.

We can use the entity number &#8217; to escape the apostrophe sign in HTML. We can also use the entity name &rsquo;, which is equivalent to the entity number &#8217;.

What’s more, we can even use the entity number &#x2019; to escape the apostrophe sign. The &rsquo; entity name resembles the right side quotes.

For example, write an h2 tag and write the text inside the tag, as shown in the example below. After the text, write the entity name &rsquo;.

Likewise, create a similar h2 tag with the same content, then write the entity number &#8217; after the text. Similarly, use the entity number &#x2019; in the third h2 tag.

As seen in the output, the apostrophe is escaped using both the entity number and entity name.

Example Code:

<h2>The apostrophe is written with entity name: &rsquo;</h2>
<h2>The apostrophe is written with entity number: &#8217;</h2>
<h2>The apostrophe is written with another entity number: &#x2019;</h2>

Output:

Use the Entity Number &#39; or the Entity Name &apos; to Write Apostrophe in HTML

We can also use the entity name &apos; to escape apostrophes in HTML. The apostrophe is the single quote.

However, the entity name can also be used as an apostrophe. We can use the entity number &#39; as well to escape the apostrophe.

For example, write a p tag and use the entity name &apos; after the text. Next, use the entity number &#39; in another p tag.

In this way, we can write apostrophes in HTML.

Example Code:

<p>
    Apostrophe (single quotes) using entity name: &apos;
</p>
<p>
    Apostrophe (single quotes) using entity number: &#39;
</p>

Output:

Related Article - HTML Entities