Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emoji rendered in Chrome have different widths than in other browsers

I have a page with an emoji followed by a space and some text. For example, "👥 Friends" (character is "busts in silhouette", U+1F465). In Safari and Firefox on macOS, it renders with a space between the emoji and the following text as expected.

In Chrome, however, the space appears as if it's absent:

Screenshot

If I remove the space, Chrome renders the text overlapping with the emoji. It seems like the width of emojis as rendered in Chrome is less than the actual character width.

Is there any way I can get the desired appearance (a normal-width space) cross browser without resorting to an image or icon font? I've tried messing with some CSS properties like text-rendering without success.

<style>   .friends {      font-family: Helvetica, Arial, sans-serif;    } </style> <span class="friends">👥 Friends</span> 

JSFiddle

like image 556
Harrison Liddiard Avatar asked Feb 03 '17 03:02

Harrison Liddiard


1 Answers

I had the same issue, and found out that it happened on non-retina screens only.

To fix it, we applied a margin through a media-query like this:

<span class="friends"><span class="emoji">👥</span> Friends</span>  <style>   @media   not screen and (min-device-pixel-ratio: 2),   not screen and (min-resolution: 192dpi) {     span.emoji {       margin-right: 5px;     }   } </style> 

This is a pretty minimal media-query. You should probably use a more complete one like https://stackoverflow.com/a/31578187/1907212.

like image 188
Julien Ma Avatar answered Sep 18 '22 09:09

Julien Ma