Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 + UTF-8: do i need to encode the GBP symbol (£)?

I thought utf-8 would be able to handle just a neat £ instead of having to convert to entities?

What's the proper way of handling the GBP symbol with UTF-8 and HTML5?

(ps. don't think the html5 part should make any difference)


update:

Here's test document:

<!doctype html>  
<head>
  <meta charset="utf-8">
  <title>GBP Test</title>
</head>

<body>
£55
<br />
&pound;55
</body>

Thanks everyone for your help.

For anyone else facing this frustration the issue comes with your text editor. Even Notepad formats in non utf-8.

SOLUTION:

Changed Read and Write formats to UTF-8 in my text editor (PHP Designer)

like image 296
Haroldo Avatar asked Nov 18 '10 15:11

Haroldo


People also ask

Which of the following is recommended character encoding to be used in HTML5?

The HTML5 specification encourages web developers to use the UTF-8 character set.

What does UTF-8 do in HTML?

The HTML5 Standard: Unicode UTF-8 Unicode enables processing, storage, and transport of text independent of platform and language. The default character encoding in HTML-5 is UTF-8.

What is the default character encoding HTML5?

The default character encoding for HTML5 is UTF-8.


2 Answers

Just use the character. It will work fine.

The symbol has a different code point in UTF-8 than in ISO-8859-1 of course. A ISO-8859-1 encoded pound sign will not work in UTF-8, and vice versa. You'd have to convert it.

Related: When Should One Use HTML Entities

like image 181
Pekka Avatar answered Sep 23 '22 20:09

Pekka


The short answer is that you don't need to use entities for most characters as long as you declare the documents character set to UTF-8 (using either a Content-Type header, a meta charset element in the head, or an xml encoding attribute with XHTML)...

The only characters you NEED to encode in a UTF-8 HTML document are (Depending on the context):

  • &amp; => &
  • &lt; => <
  • &gt; => >
  • &quot; => "

And if you are using XHTML (which is also valid XML), you also need to encode single quotes with either (again, depending on the context):

  • &apos; => '
  • &#39; => '
  • &#x0027; => '

(Note that the last 2 are preferred, since &apos; is not defined in HTML...)

Also note that &, < and > need to be escaped everywhere, and " and ' only need to be escaped inside of the appropriate attribute (so if an attribute is quoted using ", you'd need to escape all other " characters inside of that attribute)...

See the HTML 5 Draft for more information...

like image 28
ircmaxell Avatar answered Sep 20 '22 20:09

ircmaxell