HTML Emojis
In this page:
<meta charset="UTF-8">
&#emoji_number;
What is an Emoji in HTML?
Emojis are actual text characters mapped inside the universal Unicode standard. Browsers read these codes and render them as colorful icons automatically.
Example: What is an Emoji in HTML?
<p style="font-size: 48px;">😀</p>
Using Decimal Code Mappings
Decimal codes are the most common way to write emojis in HTML. Every emoji code starts with an ampersand and hash symbol (&#) and ends with a semicolon (;).
Example: Using Decimal Code Mappings
<p>😀</p>
Using Hexadecimal Code Mappings
You can also write emojis using hexadecimal codes. Hexadecimal emoji codes start with an ampersand, hash, and x character (&#x) and end with a semicolon (;).
Example: Using Hexadecimal Code Mappings
<p>😀</p>
Ensuring Character Set Compatibility
To make sure your emojis display correctly on your page, you must declare UTF-8 as your document's character set inside your head tag. If you skip this declaration, the browser may display your emojis as broken, garbled symbols.
Example: Ensuring Character Set Compatibility
<head>
<meta charset="UTF-8">
</head>
<p>😀</p>
Accessible Emojis for Screen Readers
Screen readers can find emojis difficult to interpret. To make your emojis accessible to visually impaired users, wrap your emojis in a span tag with a role="img" attribute and an aria-label describing the icon.
Example: Accessible Emojis for Screen Readers
<span role="img" aria-label="Smiling face">😀</span>
- Forgetting to include the required semicolon (;) at the end of your emoji codes.
- Omitting the required UTF-8 charset declaration in your head section, causing emojis to display as broken symbols.
- Failing to add descriptive accessibility labels, which makes your emojis unhelpful for screen-reader users.
- Emojis are actual text characters mapped inside the universal Unicode standard.
- Display emojis on your webpage using simple decimal (&#) or hexadecimal (&#x) codes.
- Declare UTF-8 as your document's character set and use descriptive accessibility labels to keep your emojis accessible to everyone.
Standard Unicode emojis are fully supported across all modern web browsers natively.
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: