Reputation: 1512
Simple question, just kinda curious because I personally find it annoying to have to include these on every webpage.
Does excluding these lines:
<!DOCTYPE html>
<meta charset="utf-8">
Really damage your webpage?
Upvotes: 2
Views: 133
Reputation: 201568
It depends. Omitting one or both of them may have no effect, or it may completely ruin the page, or it may change its appearance (anything from barely noticeable to drastic), or it may improve it on some browsers.
Omitting <!DOCTYPE html>
will generally put browsers to Quirks Mode, which is really just a word for a large collection of features where browsers (differently) try to emulate old broken browsers. For new pages, this is generally bad. For old pages written to work on those old browsers, Quirks Mode may be a necessity.
Assuming that the page is in fact UTF-8 encoded, omitting <meta charset="utf-8">
may make browsers interpret its content entirely wrong at the character level, possibly causing a disaster. Much more often, the omission has no effect, because browsers will infer the encoding from HTTP headers (if the information is present there, as it should), or from a leading Byte Order Mark if present, or by heuristic analysis (i.e. guesswork based on the actual content of the data). And a very large amount of UTF-8 encoded pages contain only Ascii characters, making the character encoding issue mostly academic.
If the page is not actually UTF-8 encoded, then <meta charset="utf-8">
should not be used, of course. Omitting it won’t necessarily save the day, though. You should in that case replace utf-8
by the correct encoding name, or change the encoding of the actual data to UTF-8.
Upvotes: 2
Reputation: 1167
In practice, no it won't damage your webpage. There are millions of pages out there without these specifiers. Also because the document type is often included in the mime-type on the server and many if not all clients will default to the correct type, if not auto-detect it, there is really no compelling reason to include those extra bytes.
Now if you're using some kind of web designer solution or content management software that requires those, then the answer could be different.
EDIT: I guess I should clarify that if you're using newer HTML features (ie, HTML5) you should at least have the basic html doctype in there. But your question was will it damage your webpage, and for many webpages (especially simple ones not using advanced features) it will not damage your page at all if you exclude the doctype. And as another mentioned, as UTF-8 is the default encoding it shouldn't matter either.
Upvotes: 0