17

The euro (€) is the official currency in 22 European states.

In HTML there are different possibilities to display the sign €:

  • €
  • €
  • €

Which one would you use in HTML? I think no representation is supported in all browsers. It's a pity that there is no standard way to display the sign.

Can you recommend one of the representations? What are the differences? Which ist supported best?

I hope you can help me. Thank you very much in advance!

caw
  • 30,999
  • 61
  • 181
  • 291

6 Answers6

38

Which one would you use in HTML?

None of them. Use an appropriate encoding (i.e.: UTF-8 or another Unicode transform) and use the charcter directly. Do not use HTML entities if at all avoidable, since they’ve got no advantage over use of a proper encoding.

Also, this is wrong:

It's a pity that there is no standard way to display the sign.

There is, and it’s the way I’ve described. Literally every browser, down to and including MSIE 5 will display Unicode characters correctly if the chosen fond supports the glyph.

The only valid reason to not use Unicode characters and instead fall back to entities might be projects that use legacy software which doesn’t support Unicode well. But that should never happen, right?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • 1
    Thanks! So since I use UTF-8, I should use €, right? Is this really better than the entities? Better supported? – caw Sep 06 '09 at 15:07
  • 10
    +1. This is 2009, we should all be using UTF-8 by now. You typed the € directly in your SO question, you should type it directly in your web page! – bobince Sep 06 '09 at 15:07
  • marco: Look at my update. Yes, it is better supported, even legacy browsers display it without troubles (heck, even Lynx does, properly set up). Fonts that contain the € symbol have been around for ages and all standard web fonts (i.e. the only ones that *should* be used since they’re the only ones with sufficient widespread support) do contain it. – Konrad Rudolph Sep 06 '09 at 15:09
  • Unfortunately, it doesn't work for me. There is a box with two numbers instead of the € if I use € => http://i25.tinypic.com/bf5o55.png Why is this? – caw Sep 06 '09 at 16:26
  • You're not using the right encoding. Use a Unicode-aware editor. – Ms2ger Sep 06 '09 at 18:07
  • I don't think that my editor (Proton) is not unicode-aware. The ä (ä) works fine for example. Only the € (€) doesn't work as you can see on the picture. – caw Sep 06 '09 at 18:57
  • marco: That’s an encoding problem. Make sure that the encoding that is sent to the web browser corresponds with the encoding of your document/data. Feel free to open a new question if you can’t resolve this issue, since the comment space here isn’t very well suited to discuss the problem and its solutions. – Konrad Rudolph Sep 06 '09 at 19:17
  • 2
    You have saved your file as Windows-CP1252 encoding (Western European), and are serving it as ISO-8859-1 encoding, which similar to CP1252 but not the same. That's why the euro ends up as a control character (U+0080). Most likely you are serving your page without any charset data at all, so the browser is guessing which you mean, which may be confusing you. Add a element to the to specify which charset you mean. – bobince Sep 07 '09 at 13:00
  • 1
    You would be best off saving the file as UTF-8 and serving it as UTF-8, but Proton is an old-fashioned editor that does not support Unicode at all. I wouldn't recommend it. Typing 'ä' to get 'ä' is just silly. – bobince Sep 07 '09 at 13:02
  • @bobince: Most browsers actually mistakenly treat ISO-8859-1 as Windows-1252 (at least on Windows), since a lot of older websites used the encoding incorrectly. At least, that was definitely true only a few years ago, in Firefox as well as MSIE. I don’t know if they’ve finally fixed that behaviour. – Konrad Rudolph Sep 07 '09 at 13:23
  • That's true. I guess the question is where Marco got the idea that ISO-8859-1 '€' (0xC2, 0x80) was the same byte sequence as UTF-8 '€' (should be 0xE2, 0x82, 0xAC). That's the point at which the confusion between cp1252 and 8859-1 happened. Marco: if you are dead set on typing bytes into your editor in cp1252 that'll come out as characters in UTF-8, the string you want is '€'. But you're better off with a proper text editor. – bobince Sep 08 '09 at 01:48
9

According to Google Doctype € is supported in all browsers. But maybe not all fonts.

edit I also agree with Konrad Rudolph, use the character directly if you can.

Josef Pfleger
  • 74,165
  • 16
  • 97
  • 99
  • It seems that it doesn't work in Internet Explorer 8 if you use the font Courier New. – caw Sep 06 '09 at 15:55
2

From Google's HTML/CSS styleguide:

Do not use entity references. There is no need to use entity references like —, ”, or ☺, assuming the same encoding (UTF-8) is used for files and editors as well as among teams.

The only exceptions apply to characters with special meaning in HTML (like < and &) as well as control or “invisible” characters (like no-break spaces).

<!-- Not recommended -->
The currency symbol for the Euro is &ldquo;&eur;&rdquo;.

<!-- Recommended -->
The currency symbol for the Euro is “€”.
Wouter Dorgelo
  • 11,770
  • 11
  • 62
  • 80
  • Thanks, sums everything up very well. – caw Jul 03 '12 at 19:06
  • 2
    I forgot to post it, but here's Google's official styleguide: http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml – Wouter Dorgelo Jul 03 '12 at 21:25
  • And here's the new link for everyone reading this and finding out, that the link doesn't work anymore.. ;) https://google.github.io/styleguide/htmlcssguide.xml – Dennis98 Jun 30 '16 at 16:59
1

You should really just test it and specify those browsers that support it as minimum requirements. This eases your workload considerably since it makes the user responsible :-) Or, alternatively, use the word "euro" or the "EUR" curruncy designator (like USD, AUD, JPY and so on).

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
0

I use &#128; as you can see here : € it works in Firefox, Chrome and IE at least.

Sergio Abreu
  • 2,686
  • 25
  • 20
0

The accepted answer is actually awful,at least as of today. Best choice is to use &euro;

&#128; is not Unicode, btw, even though it works. It's ANSI. JavaScript String.fromCodePoint(128) will give you a control character you won't even be able to see. Stay away from that.

If you're going to use plain UTF-8 text for symbols you might end up having mistakes after changing db properties, or if you're just typing it into file, once you accidentally copy it into an ANSI-coded, or some a file with some other encoding. Been there.

Íhor Mé
  • 896
  • 9
  • 13