I've always wondered whether whitespace before a DOCTYPE matters, but I can't seem to find any definitive information on the web. People say not to do it, but I can't see what effect it's likely to have, or even if the spec says it must be like that. I can't figure out if it triggers compatibility mode in IE or anything annoying like that.
The reason is, in my (crappy asp.net) code, I would much prefer to write:
<%@ Page language="c#" Codepage="65001" AutoEventWireup="true" %> <%@ OutputCache Location="None" VaryByParam="none" %> <!doctype html>
than:
<%@ Page language="c#" Codepage="65001" AutoEventWireup="true" %><%@ OutputCache Location="None" VaryByParam="none" %><!doctype html>
Because the first is neater. But the result of the top one is a few blank lines in your rendered html.
Not a huge issue. I've just always wondered if it matters :)
The HTML document type declaration, also known as DOCTYPE , is the first line of code required in every HTML or XHTML document. The DOCTYPE declaration is an instruction to the web browser about what version of HTML the page is written in.
The absence of the DOCTYPE or its incorrect usage will force the browser to switch to quirks mode. It means that the browser will do its best to layout the page that is considered to be old or created against web standards.
Definition and Usage All HTML documents must start with a <! DOCTYPE> declaration. The declaration is not an HTML tag. It is an "information" to the browser about what document type to expect.
DOCTYPE> tag is the very first line in the HTML document. It tells the browser what version of HTML the document is written so that the browser knows what to expect. This tag is also commonly referred to as the <! DOCTYPE> element.
Yes! comments and spaces may come first.
Here's the relevant section from the official HTML Specification
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With