Favorites

Using Emojis With CSS & HTML

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Emojis

Emojis have become a universal language: a single character can show emotion, add context or catch the eye. On the web, they can liven up headings, mark success and warning messages, and add personality to buttons and lists, all without loading a single image file.

In this post we'll look at the different ways to add emojis to your pages, how to style them with CSS, how to keep them accessible, and some handy tools for working with them, including an Emoji CSS Generator and a complete emoji reference.

Adding emojis in HTML

1. Typing the emoji directly

The simplest method is to type or paste the emoji straight into your HTML:

<p>Welcome to our website! 😄🎉</p>

This works everywhere, as long as your file is saved as UTF-8 (the standard text encoding, and the default in modern code editors) and your page includes <meta charset="utf-8">. It's also the easiest to read in your code.

2. Using HTML character references

You can also write an emoji as a numeric character reference: its Unicode code point in decimal, or in hexadecimal with an x:

<p>Party time! &#127881;</p>     <!-- decimal: 🎉 -->
<p>Party time! &#x1F389;</p>    <!-- hexadecimal: 🎉 -->

Character references are handy when your editor or workflow struggles with special characters, but they produce exactly the same character as typing the emoji directly.

3. Adding emojis with CSS

In CSS, emojis can be added with the content property on a ::before or ::after pseudo-element, either typed directly or as a CSS escape (a backslash followed by the hexadecimal code point):

.new::after {
  content: " 🎉";
}

.tip::before {
  content: "\1F4A1  ";  /* 💡, then a space */
}

For more on CSS escapes and their gotchas, such as why "\1F4A1 " needs two spaces, see our post on using Unicode characters in CSS.

Tip: for a complete range of emojis, with their HTML codes and CSS escapes ready to copy, take a look at CharacterCodes.net Emojis.

How emojis look on different devices

Emojis are drawn using the device's own emoji font, so the same emoji looks different on Windows, macOS and iOS, Android and Linux. A 😄 on an iPhone isn't quite the same as a 😄 on a Windows laptop.

  • New emojis may not display everywhere. Each year, new emojis are added to Unicode, and older devices without an updated emoji font may show them as an empty box (often called "tofu"). Stick to well-established emojis for anything important.
  • Some emojis are made of several characters. Skin tones, flags and family emojis combine multiple code points into one picture. On devices that don't support a combination, they may appear as separate emojis side by side.
  • Custom fonts can interfere. If your site uses a web font that includes some symbols, a few emojis may appear as plain black-and-white symbols. You can add the main emoji fonts to the end of your font-family, so emojis are drawn with a colour emoji font where possible:
body {
  font-family: "Inter", system-ui, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
}

CSS also has a font-variant-emoji property, which asks the browser to show characters such as ⚠ and ❤ either as text symbols or as colourful emojis. It isn't supported in every browser yet, so treat it as an extra rather than something to rely on.

Emojis and accessibility

Screen readers (software that reads pages aloud) announce emojis using their official names. "Great job 👏👏👏" is read as "Great job, clapping hands, clapping hands, clapping hands", which gets tiresome quickly. A few simple habits help:

  • Hide decorative emojis that don't add meaning, so they aren't read out:
    <h2>Our summer sale <span aria-hidden="true">☀️🏖️</span></h2>
  • Label meaningful emojis whose official name doesn't match what you mean, using role="img" and aria-label:
    <p><span role="img" aria-label="Warning">⚠️</span> This action can't be undone.</p>
  • Don't use emojis instead of words for important information. "✅" on its own might mean done, correct, included or approved. Pair it with text such as "Done".
  • Use them sparingly, and avoid placing several in a row.

Styling emojis with CSS

Emojis are text characters, so most text styles apply to them.

Size

Use font-size to make an emoji bigger or smaller:

.emoji-small  { font-size: 1rem; }
.emoji-medium { font-size: 2rem; }
.emoji-large  { font-size: 3.5rem; }
Results
1rem
2rem
3.5rem

Shadows and filters

Colour emojis keep their own colours, so the color property doesn't change them. Shadows and filters do work, though:

.emoji-glow {
  text-shadow: 0 0 12px gold;
}

.emoji-faded {
  filter: grayscale(1);
  opacity: 0.6;
}

.emoji-tinted {
  filter: hue-rotate(160deg);
}
Results
Normal
Glow
Greyscale
Hue rotated

A greyscale filter is handy for showing an inactive state, such as an achievement that hasn't been unlocked yet.

Movement

Emojis can be transformed and animated like any other element. Give them display: inline-block first, as transforms don't apply to plain inline text. Hover over the emojis:

.emoji-wiggle {
  display: inline-block;
  transition: transform 0.3s ease;
}

.emoji-wiggle:hover {
  transform: scale(1.3) rotate(-12deg);
}
Results

Emoji list markers

You can even use an emoji as a list bullet with list-style-type:

ul.checklist {
  list-style-type: "✅\00A0\00A0";  /* the emoji, then two non-breaking spaces */
}
Results
  • Save the file as UTF-8
  • Hide decorative emojis from screen readers
  • Use emojis sparingly

Boost your workflow: the Emoji CSS Generator

If you use lots of emojis across a site, the Emoji CSS Generator saves a lot of manual work. Instead of copying individual emoji characters and writing CSS for each one, you choose the emojis you want and download a ready-made CSS file with a class for each.

What the generator does

  • Lets you browse a full emoji library and pick the ones you need.
  • Produces a CSS file with a class for each emoji you selected.
  • Includes size classes, so you can make an emoji bigger or smaller just by changing a class.
  • Lets you display an emoji with simple HTML such as <i class="eh eh-heart"></i>.

Why it helps

  • Consistency: one CSS file and reusable classes keep emojis looking the same across your whole site.
  • Cleaner code: no repeated inline styles or hard-to-read character codes.
  • Easy to customise: add your own CSS on top of the generated classes for hover effects, shadows or animations.
  • Quick to set up: pick emojis, download the CSS, link it, and you're done.

How to use it

  1. On the Emoji CSS Generator page, choose the emojis you want, such as a heart ❤️, a rocket 🚀 and a tick ✅.
  2. Click Download CSS to get a file (for example, emojicss.css) containing classes such as .eh-rocket and .eh-heart.
  3. Link the file in the <head> of your page:
    <link rel="stylesheet" href="css/emojicss.css">
  4. Add emojis to your HTML, using the size classes as needed:
    <i class="eh eh-rocket eh-x2" aria-hidden="true"></i>
    <i class="eh eh-heart eh-x15" role="img" aria-label="Love"></i>

    Here, .eh-x2 and .eh-x15 are size classes provided by the generator.

  5. Optionally, add your own CSS for hover effects, shadows or animations to match your design.

Tip: as with any emoji, add aria-hidden="true" to decorative ones, and role="img" with an aria-label to ones that carry meaning, as in the example above.

Emojis and SEO

Emojis can make titles and descriptions stand out, but there are a few things to keep in mind:

  • Search engines may not show them. Emojis in your <title> and meta description are allowed, but search engines decide whether to display them, and often remove them, especially if they seem distracting or irrelevant. Don't rely on them appearing.
  • They don't boost rankings. Emojis are treated like other characters. They neither help nor harm your position in results, so use them for readers, not for SEO.
  • One is plenty. A single relevant emoji can add personality; a string of them looks spammy and gets read aloud by screen readers.
  • Think about headings. An emoji in a heading is read out every time someone navigates by headings. If it's decorative, wrap it in <span aria-hidden="true">.
  • Social posts are a natural fit. Emojis in link-sharing text and social posts are common and expected, and can help your message stand out in a busy feed.

Wrapping up

Emojis are a lightweight way to add personality and visual cues to your pages. Type them directly or use character references, style them with font-size, shadows, filters and transforms, and remember they look different on every device. Hide decorative emojis from screen readers, label meaningful ones, and use them sparingly. When you're working with lots of them, the Emoji CSS Generator and CharacterCodes.net Emojis will save you plenty of time.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee