DEV Community

Dwayne Crooks
Dwayne Crooks

Posted on • Updated on

Using special HTML characters in Elm

NOTE: Works for Elm 0.19.

If you attempt to display the copyright symbol using the following:

view = text "©"
Enter fullscreen mode Exit fullscreen mode

Then you'd literally see ©.

In order to get © you need to use Unicode escape characters.

view = text "\u{00A9}"
Enter fullscreen mode Exit fullscreen mode

It's that simple.

If for any reason you mess up the escaping syntax (maybe you forget the curly braces, like a "friend" of mine did ;)) then Elm has your back with this insanely helpful error message.

Unicode escape characters error message

BTW, you can lookup the hex codes for what you need here.

P.S. I needed to figure this out when I had to output a non-breaking space in my Drum Machine project.

Discussion (3)

Collapse
robertlj_8 profile image
Robert Johnson

Thanks for the article!!! I had no idea you could do this in Elm

Collapse
dwayne profile image
Dwayne Crooks Author

You're welcome.

Collapse
remo profile image
Remo Zaros • Edited on

Good stuff! It's little stuff like this that can easily turn into a source of fustration.