Prevent text glyphs from turning into emojis
Last year I had an interesting task to make a heart symbol a part of a page title. We were organizing ’Ya Love Frontend’ conference (Ya is for Yandex, but it sounds the same as ’I’ in Russian), and we used the UTF-8 heart symbol to make the title more emotional.
So, what’s the problem?
If you have the title ’I ❤ Frontend’, it is rendered differently in different browsers on different operating systems. For example, on Android and iOS it looks like emoji. And that’s a huge problem if you have to style the title.
It’s all about rendering. Nikita Prokopov described it in his detailed article about emojis.
Every symbol you use has its UTF-8 sequence. For example, letter A is
U+0041, letter Z is
U+005A, $ is
U+0024, etc. The same is for emoji, ❤ is
You can even paste it into your HTML as a Unicode sequence, not a symbol.
<span>I ❤ Frontend</span>
<span>I ❤ Frontend</span>
&#x is for Unicode prefixing.
But what if the current font hasn’t any glyph that can render your UTF-8 symbol? OS tries to find any font that has that glyph. So, iOS will find the Apple Color Emoji font, Android will find the Noto Color Emoji font, etc. And it looks like we have some possibilities to control it.
The first decision is to have a font that has all your necessary glyphs. For example, Arial. Or some custom font. You need to add that font to font fallbacks in your CSS.
font-family: 'Text Font', 'Custom Glyphs Font', sans-serif;
I don’t like such solutions because I can’t control all the glyphs in the text. Especially if I have some kind of content management system. And it’s a pain to rebuild the font every time I need a new glyph.
Luckily, we have another option. UTF has special characters to control the rendering.
U+FE0E asks OS and browser to render the previous glyph as text,
U+FE0F asks to render the previous glyph as emoji.
So, let’s try to use it.
<li>☀ can be rendered differently.</li>
<li>☀️ should look like a sun emoji.</li>
<li>☀︎ should look like a sun text symbol.</li>
- ☀ can be rendered differently.
- ☀️ should look like a sun emoji.
- ☀︎ should look like a sun text symbol.
So, if you need to disable emoji in your text, convert the symbol to UTF-8 or UTF-16 sequence (
symbol.codePointAt(0).toString(16)), than add
︎ to it.
<span>I ❤︎ Frontend</span>
But it won’t work for the heart emoji on Android. I don’t know why. When we tested it last year, it was ok, but… You can play around with different emojis in this sandbox. As for me, something is better than nothing.
Remember that all emojis have text representations. For example, ⭐︎ is
white medium star, ► is
black right-pointing pointer, etc. And screen readers will use these texts.
I ❤ Frontend becomes
I Red Heart Frontend. I suppose we didn’t mean that.
To fix it, use the glyph the right way.
<span role="img" aria-label="Love">❤</span>
And the final result we used on the conference website is below.
I <span role="img" aria-label="Love">❤︎</span> Frontend!
Webmentions [?], ❤︎ 17
На лайве у @pepelsbey прозвучал вопрос: «Как помешать браузеру рендерить символы-иконки в виде эмодзи?» В прошлом году решал такую проблему для сайта конференции «Я 💛 Фронтенд», поделился опытом в блоге 🙃