1. Home
  2. Guides
  3. Emoji for Developers: Unicode, HTML, CSS, JavaScript and Storing Emoji in a Database

Emoji for Developers: Unicode, HTML, CSS, JavaScript and Storing Emoji in a Database

A practical guide to handling emoji in web pages and apps: code points and emoji sequences, HTML entities, CSS content, JavaScript string length and Intl.Segmenter, regex, MySQL utf8mb4, URL and JSON encoding, fonts and accessibility, with examples.

Emoji look like pictures, but inside a program they're text. That means there are moments when they don't behave like ordinary letters: when you count characters, store them in a database or cut a string short. This guide walks through common problems people building websites and apps run into with emoji, in roughly the order you'll meet them.

Every emoji page on EmojiCanvas has a β€œDeveloper codes” section near the bottom with the code points, HTML hex and decimal entities, CSS, JavaScript and URL-encoded values, each with a copy button. It's handy to keep one open while reading.

One emoji can be several code points

Unicode gives every character a number called a code point. πŸ˜€ is a simple emoji made of a single code point, U+1F600. But a lot of things that appear on screen as one emoji are actually sequences of several code points.

The guide on how combined emoji work explains this with pictures. The one thing to remember while coding: what a person sees as one character and what your program counts as characters can be different numbers.

Putting emoji in HTML

The simplest approach is to type the emoji straight into your HTML. For that to work, the document needs <meta charset="utf-8"> inside the head, and the file itself has to be saved as UTF-8. If either one is off, emoji turn into garbled characters.

If you can't be sure of the file encoding, use numeric character references. πŸ˜€ is &#x1F600; in hex or &#128512; in decimal. Sequences need one reference per code point, so ❀️ becomes &#x2764;&#xFE0F;.

Using emoji in CSS

To put an emoji in a pseudo-element, use a backslash and the hex value in the content property: content: "\1F600"; for πŸ˜€. Sequences are chained, so ❀️ is content: "\2764\FE0F";.

To make sure emoji are drawn with the system's color emoji font, add emoji fonts at the end of your font stack. A common choice is "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji". Without them, some environments pick up a black-and-white symbol from a regular font first.

JavaScript string length

JavaScript strings are stored as UTF-16 code units. Code points above U+FFFF, like πŸ˜€, take two units (a surrogate pair), so "πŸ˜€".length is 2.

Finding emoji with regular expressions

Hand-written ranges for β€œmatch any emoji” are easy to get wrong. Unicode properties are more reliable.

Storing emoji in MySQL: use utf8mb4

MySQL's old utf8 character set (now called utf8mb3) stores at most 3 bytes per character. Emoji take 4 bytes in UTF-8, so saving them there either fails with an β€œIncorrect string value” error or turns them into question marks.

PostgreSQL stores emoji without extra setup as long as the database encoding is UTF8.

Length means different things in different languages

The same emoji gets counted differently depending on the language.

For any input with a character limit, make sure the front end and the server count the same way. That's where the classic β€œpassed in the browser, rejected by the server as too long” bug comes from.

Emoji in URLs and JSON

In a URL, an emoji becomes its UTF-8 bytes in percent-encoding: πŸ˜€ is %F0%9F%98%80. In JavaScript, encodeURIComponent() does this for you.

JSON can carry emoji as-is, but some libraries output surrogate pair escapes like \ud83d\ude00. Python's json.dumps() does this by default; pass ensure_ascii=False to keep the emoji as written. Both forms decode to the same character, so compare decoded values rather than raw JSON text.

The device decides what it looks like

The code is the same everywhere, but the picture comes from the emoji font of the OS or app. That's why one emoji looks different across devices, and why newer emoji can show up as empty boxes (β–‘) on older systems. The guide on emoji that show as boxes covers the causes.

If every user must see the same artwork, you can render emoji as images instead. Check the license when you do. Google Noto Emoji artwork is Apache 2.0 (the font files are OFL 1.1), Twemoji is CC BY 4.0 (attribution required) and Microsoft Fluent Emoji is MIT. Apple's and Samsung's emoji artwork isn't openly licensed, so it can't be reused. Each emoji page on EmojiCanvas lets you download PNG and SVG files of those three designs.

Accessibility: screen readers read the name

Screen readers announce an emoji by its name. Put πŸ”₯πŸ”₯πŸ”₯ in a heading and listeners hear β€œfire, fire, fire.”

Pre-launch checklist

Last checked 2026-11-06

Emoji in this article

When on, tapping an emoji adds it to the tray below.

Emoji with a blue dot open a meaning guide. The rest are copied as soon as you tap them.

Related reading