Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

charset=iso-8859-1 with <!DOCTYPE HTML> throwing a warning?

I just validated an HTML document using the W3C validator, and found that if I use:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

with:

<!DOCTYPE HTML>
  • It throws a warning Line 4, Column 72: Using windows-1252 instead of the declared encoding iso-8859-1.

However, it is fixed if I use:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

I don't really understand what is happening. Also, I don't even know how to use the DOCTYPE tag, I just copied and pasted one from around the web.

  • Why does this happen?
  • How should I use the DOCTYPE tag?
like image 230
ajax333221 Avatar asked Jan 03 '12 05:01

ajax333221


3 Answers

Changing the DOCTYPE is simply turning off the warning - it isn't actually fixing anything.

iso-8859-1 and windows-1252 are very similar encodings. They differ only in the characters associated with the 32 byte values from 0x80 to 0x9F, which in iso-8859-1 are mapped to control characters and in windows-1252 are mapped to some useful characters such as the Euro symbol.

The control characters are useless in HTML, and web authors often mistakenly declare iso-8859-1 and yet use one or more of those 32 values as if they were using windows-1252, so browsers when they see the iso-8859-1 charset being declared will automatically change this to be windows-1252.

The validator is simply warning you that this will happen. If you're not using any of the 32 byte values, then you can simply ignore the warning - it's not an error. If you are, and you genuinely want the iso-8859-1 interpretation of the byte values and not the windows-1252 interpretation, you are doing something wrong.

Again, this switching happens in browsers for any DOCTYPE, it's just that the HTML5 validator is being more helpful about what it is telling you than the HTML4 validator is.

like image 181
Alohci Avatar answered Nov 18 '22 05:11

Alohci


A couple of points:

  1. Any HTML5 validation should be taken with a grain of salt. The specification is still under active development, and not everything is set in stone.
  2. You're using the HTML4 syntax for that meta tag. Try <meta charset="iso-8859-1">

That said, HTML validators don't serve that much purpose in this day and age.

But apparently the default for HTML4 was iso=8869-1. That said, the default charset for HTML5 is UTF-8.

More information about the HTML5 doctype can be found in this post by John Resig.

like image 7
Andrew Stewart Avatar answered Nov 18 '22 05:11

Andrew Stewart


It throws a warning Line 4, Column 72: Using windows-1252 instead of the declared encoding iso-8859-1.

It means the file was saved with the encoding Windows-1252 on creation (AKA Western Windows 1252 or CP1252) and your charset declaration says "hey read this file with ISO 8859-1" when that's not the encoding the file has.

The meta charset exist for that reason. It exist to declare the encoding of the file you are sending/reading/using so when, for example a browser, reads the document it knows what encoding the file is using.

In detail, you have this charset declared:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

But the file you are validating is actually encoded in Windows-1252. How? Why? Check the text editor you are using and what encoding it is using to save files. If the editor can be configured to change the encoding, choose the one you want to use.

About HTML5

Using

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

or

<meta charset="iso-8859-1">

are both valid for HTML5. See <meta charset="utf-8"> vs <meta http-equiv="Content-Type">

like image 3
delroh Avatar answered Nov 18 '22 06:11

delroh