Search code examples
utf-8doctypehead

How to Properly Define UTF-8 Charset in in <head> Tag Section of Web Document


If my doc type is <!DOCTYPE html> is it best or more correct to use

<meta charset="utf-8" />

or

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

to define utf-8?

Thanks.


Solution

  • The first one is only valid with HTML5. The second one is also valid for older (X)HTML versions

    With this doctype (indicating HTML5) both are valid, I prefer the first as it is shorter. :)