44

When writing a html 5 doctype, are you supposed to include the <html xmlns="http://www.w3.org/1999/xhtml"> as you did when previously using HTML4 doctype or should a different xhtml be used?

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml">
6
  • 3
    w3.org/html/wg/drafts/html/master/… suggests that this is not necessary. Commented Jan 28, 2013 at 14:12
  • HTML 4 doctypes do not require or even allow an xmlns attribute. Commented Jan 28, 2013 at 17:02
  • @JeremyHolovacs, the link is broken. Commented Feb 21, 2014 at 3:56
  • @PaulDraper yeah apparently it is not a draft any more... w3.org/TR/html5/dom.html#dom-tree-accessors Commented Feb 21, 2014 at 12:40
  • 1
    I found this link to be helpful: diveintohtml5.info/semantics.html Commented Feb 23, 2015 at 20:51

3 Answers 3

48

HTML5 does not require the use of the xmlns attribute as that is specific to XHTML (which means not even HTML 4 uses it either).

If you're just serving regular HTML5, then you can leave out that attribute entirely:

<!DOCTYPE html>
<html>

The xmlns attribute is only required if you're writing and serving XML-serialized HTML5, aka XHTML5.

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

5 Comments

I know this answer is currently >1 year old, but I don't think XHTML5 exists any more? If that is true, then is xmlns ever used?
@MyDaftQuestions: That question is misguided - there has never been a distinct standard called XHTML5; the development of XHTML that was abandoned in favor of HTML5 is XHTML 2.0, which has nothing in common with HTML5 or XHTML5. As I state in my answer, XHTML5 is nothing more than HTML5 serialized as XML.
Ah, that is now clear - great explanation, thank you
And does the presence of the unneeded xmlsn attribute have any side effect?
@matteo: The spec says that it has absolutely no effect and is nothing more than a relic.
25

No, you don't need to include it. This should be enough.

 <!doctype html>
 <html> 

4 Comments

best answer as it came first
While it's totally up to you which answer to accept an answer is not really the "best" one just because it's the first one. For example, I really miss an explanation of the "why" in this answer.
@ThiefMaster I know what you mean, what I meant to say was that I wanted to know if I need it or not, and as this person said its not needed (and others said not needed) then mohammad is correct and as he is is first correct then that is why I marked it best answer. But additional details from other people is great for other people to see if required. Problem is what I can see happening which has happened before is if multiple people have similar answers and I don't mark the answer the first person answered, then they become unhappy and let me know :)
@ThiefMaster agreed, and not only would an explanation be helpful but also citing references. The number of times people answer questions on this site without linking to resources… as if they just pulled it right out of their head…
-4

No you don't. In fact, if you include it, then it isn't HTML5, it's xhtml.

The xmlns part is an XML namespace reference. HTML5 is not XML.

In fact, if you were using that xmlns previously, then you weren't using HTML4 either, you were using xhtml. They're not the same.

1 Comment

If you include the xmlns attribute, the document is still HTML5.

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.