Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is It Safe To Use Unicode Literals in HTML?

Tags:

html

unicode

I am making an application, and I want to add a "HOME" button.

After much struggling with various icon libraries, I stumbled upon this site,

http://graphemica.com/%F0%9F%8F%A0, with this

🏠

A unicode symbol, which is more akin to a letter than an image.

I pasted it into my HTML, and it just workedTM.

All this seems a little too easy, though. Are unicode symbols widely supported? Is there some kind of problem with them that leads people to use icon libraries instead?

like image 950
Code Whisperer Avatar asked Apr 27 '18 10:04

Code Whisperer


People also ask

Can I use Unicode in HTML?

You can enter any Unicode character in an HTML file by taking its decimal numeric character reference and adding an ampersand and a hash at the front and a semi-colon at the end, for example — should display as an em dash (—). This is the method used in the Unicode test pages.

Does HTML use Ascii or Unicode?

The ASCII Character Set It contains the numbers from 0-9, the upper and lower case English letters from A to Z, and some special characters. The character sets used in modern computers, in HTML, and on the Internet, are all based on ASCII. The following tables list the 128 ASCII characters and their equivalent number.

How do I use Unicode Icons?

Inserting Unicode characters To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X.

How do I use HTML code points?

The Unicode and HTML Entities for Bullet Points The Unicode character for showing the dot symbol or bullet point is U+2022 . But to use this Unicode correctly, remove the U+ and replace it with ampersand ( & ), pound sign ( # ), and x . Then type the 2022 number in, and then add a semi-colon. So, it becomes • .


2 Answers

Some things you want to make sure you’re doing:

  • Save your HTML file as UTF-8. In fact, save all text files as UTF-8 unless there’s some reason you can’t.
  • Put the line <meta charset="utf-8" /> near the top of your HTML file.
  • Make sure your server isn’t misconfigured to tell all browsers that webpages are in the wrong encoding.
  • If, somehow, it is and you can’t fix it, fall back on &entities;.
  • Specify a font stack for your emoji in CSS with a set of fonts that cover nearly every system, perhaps including Apple Color Emoji, Noto Color Emoji, Segoe UI Emoji and Twemoji.
  • If a free font such as Noto or Symbola contains the emoji you use, you can package it as a WOFF to be sure it will always display the way you want. (As of 2018, Tor browser does not show most emoji correctly by default, but mainstream browsers do.)
like image 192
Davislor Avatar answered Oct 10 '22 08:10

Davislor


It depends on what do you mean for "safe".

User should have the fonts, so you must include the relative font, and in various formats: there is not yet a format recognized by most used web-browsers.

Additionally, font with multiple colours are not fully understood by various systems, so you should care about what do you expect from users (click, select, copy, etc.).

Additionally, every fonts has own design, so between different fonts (so browsers and operating system) things can look differently. We do not have yet a "Helvetica 'Home'", a "Times New Roman 'Home'".

All this points, could be solved by using a web font, with monochrome glyphs (but it could be huge, if it includes all Unicode code points (+ usual combinations).

It seems that various recent browser crashes if there are many different glyphs, but usually it should not be a problem.

I also recommend aria stuffs so that you page could be used also by e.g. readers (and braille screen).

Note: on the plus side, the few people that use text browser can better see the HOME (not the case in case of an image), if somebody still care about this use case.

like image 31
Giacomo Catenazzi Avatar answered Oct 10 '22 08:10

Giacomo Catenazzi