Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring character encodings in HTML [duplicate]

Should I declare charset like this:

<meta http-equiv="content-type" content="text/html" charset="utf-8" />

or like this:

<meta http-equiv="content-type" content="text/html; charset=utf-8"/>

Or are both valid?

like image 482
Menel Avatar asked Jul 08 '16 21:07

Menel


People also ask

What is the correct way of declaring character encoding in HTML5?

Always declare the encoding of your document using a meta element with a charset attribute, or using the http-equiv and content attributes (called a pragma directive).

How do I fix the character encoding of the HTML document was not declared?

Adding <meta charset="utf-8"/> in the html code solved my issue in Firefox. Save this answer.


2 Answers

The both declarations are valid, you could always use the short equivalent version :

<meta charset="utf-8" /> 

Hope this helps.

like image 78
Zakaria Acharki Avatar answered Oct 22 '22 12:10

Zakaria Acharki


Because you start a document with

<!DOCTYPE html>

I doubt that it's necessary to specify the content type. Instead just specify the encoding/charset:

<head>
   <meta charset="UTF-8">
</head>
like image 3
Captain Anonymous Avatar answered Oct 22 '22 14:10

Captain Anonymous