开发者

Why is there a carriage return in the HTML 4 & XHTML !DOCTYPE declarations?

Why is there a carriage return in the HTML 4 & XHTML DOCTYPE declarations?

Eg:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitio开发者_如何学Pythonnal.dtd">

also, would there be a problem if I remove it?


It allows it to fit in a standard 80 character wide display.

You need some whitespace there, so if you remove it, you have to put a normal space there instead (so it isn't going to save you a byte of data transfer). Doing so does reduce readability though.


The carriage return is simply to break a long line up into multiple lines. It can be safely removed.

This is no different from inserting newlines between long HTML attributes to avoid having to scroll horizontally to read the whole line. The goal is legibility:

<a href="a really long URL with a big query string or something"
   title="Some longish title goes here"
   class="class1 class2 class3">Some text</a>


Code formatting.

Its just white space and safe to remove.


It is there simply for legibility and to fit into 72 characters. Can be removed safely.


It's just to make the lines short enough so that the browser doesn't break the line in an inconvenient place. If it was written in a single line and the browser broke the line in a middle of the URL, for example between the dash and "transitional", and you copied it that way, it could be invalid.

When you use it in the code you can have it on a single line, or even break it up into more lines if you would like that.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Or even:

<!DOCTYPE
html
PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜