HTML5 Character Encoding

Jakob Jenkov
Last update: 2014-06-15

You should specify the character encoding used by your HTML5 page. The character encoding should be in the first 512 bytes of your document. Here is an example:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>

</html>

The character encoding is specified in the meta element shown in bold. This meta element looks somewhat different from what you might be used to from HTML4. This shorter version is still valid though. Here is an example of the HTML4 way of specifying character encoding:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

This longer version is also still valid, but the shorter version is just easier to use, and it already works in all browsers.

In this example the character encoding is set to UTF-8. This is the recommended character encoding, although other character encodings are valid too.

If you choose UTF-8 as character encoding for your HTML5 page, you should make sure that your HTML editor also saves your HTML5 pages in UTF-8 encoding. Otherwise the page will not display correctly in the browser. If the HTML5 page is generated by a dynamic web server application, make sure that your application generates the HTML5 page in the same character encoding as you specify at the top of the page.

Jakob Jenkov

Featured Videos

Java ConcurrentMap + ConcurrentHashMap

Java Generics

Java ForkJoinPool

P2P Networks Introduction

















Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next