开发者

Doc Type Definition: A Syntax Question

开发者 https://www.devze.com 2023-02-11 01:48 出处:网络
In the top of my webpages it days:开发者_开发百科 <!doctype html><html xmlns=\"http://www.w3.org/1999/xhtml\"

In the top of my webpages it days:开发者_开发百科

<!doctype html><html xmlns="http://www.w3.org/1999/xhtml"

lang="nl" xml:lang="nl">

Q1:

Which one is more fault-proof/better in your opinion: <!doctype html> or <!doctype html/>

Q2:

I wonder whether there is anything shorter than this, which will define the language:

<html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de">

And should that be ending with > of />?

Thanks very much.


Q1: This is very simple: <!doctype html/> is wrong. The doctype is not a self-closing tag, neither in HTML nor in XML. The only valid declaration for HTML5 is therefore <!doctype html>.

Q2: That depends. You don’t actually need to declare the XML namespace if you’re using HTML rather than the XHTML variant (and the xml:lang attribute would also be pointless). In that case, the doctype (see Q1) is entirely sufficient:

<!doctype html>
<html lang="nl">
    …
</html>

On the other hand, if you want to use XHTML then you should add the XML namespace (and, yes, the xml:lang attribute). Using XHTML does have advantages, primarily because some editors/evaluators will treat errors stricter and can thus provide better diagnostics for errors.

0

精彩评论

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

关注公众号