1

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Likewise, if you're not using XML, then having the additional namespaced xml:lang attribute is pointless.
@David: That goes without saying. Or perhaps not. ;-) I’ll add it.
I wouldn't call the document language an added bonus. Making sure that screen readers get the right pronunciation database and that search engines file the document under the right language is a basic essential in my book. It is just the xml: variant that is pointless.
+1 very clear! Thanks all! Updated the question, see the '>' or '/>' on the second part pelase.
<html lang="de">, and no, only elements with no content can have a / and that is useless, optional syntactic sugar if you are writing HTML (rather than XML).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.