5

I'm trying out different web page compositors and most of them start out with a basic structure like this when I create a new project:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>New Web Project</title>
    </head>
    <body>
        <h1>New Web Project Page</h1>
    </body>
</html>

I wasn't really able to find an answer as to why there needs to be an xmlns if it's going to be a normal web page. I know I can omit it if I so desire, I've been writing HTML5 documents before and it was working fine without it.

So when is it actually necessary to provide an xmlns in the <html> element and why do compositors think it should be there when I create a new project? Is there any significance providing an xmlns with the <html> tag when doing HTML5 in the first place? Is there any benefit adding it?

SebinNyshkim
  • 169
  • 1
  • 4
  • http://stackoverflow.com/questions/1181888/what-does-xmlns-in-xml-mean. The more highly rated answer seems to answer your question. – j08691 Jun 25 '15 at 17:14
  • read more about XML on Google : http://www.w3schools.com/xml/xml_namespaces.asp – poudigne Jun 25 '15 at 17:15
  • @j08691 Thanks, that actually does answer my question. The reason I couldn't find it in searches prior to asking my question is probably because it's filed under XML rather than HTML. So, does that also mean I could theoretically define my own HTML elements *or* redefine the meaning of existing elements by providing my own `xmlns`? – SebinNyshkim Jun 25 '15 at 18:17
  • I don't see how any of the answers on that post answer this question. None of them address using `xmlns` in the `` element. – TylerH Aug 29 '23 at 21:21

2 Answers2

3

On a regular HTML5 page you don't need it. However, if you want XML-serialized HTML5 (i.e. XHTML) then you add the XML namespace. For example the web framework JSF uses XML-serialized HTML, so there would be one reason to use it.

SiCN
  • 1,052
  • 8
  • 17
2

The HTML validator at http://w3.org does not complain when the xmlns attribute is missing in an XHTML document. This is because the namespace "xmlns=http://www.w3.org/1999/xhtml" is default, and will be added to the tag even if you do not include it.

From http://www.w3schools.com/tags/att_html_xmlns.asp

Adam Buchanan Smith
  • 9,422
  • 5
  • 19
  • 39
  • 2
    I don't believe that is correct. Your link to w3schools (whose reputation for correctness is questionable) says nothing about a default namespace. It simply says it is not required in HTML5. The reason the **XML** namespace is not required in HTML5 is that HTML5 is not XML (although it can be in which case the namespace **IS** required.) It's important to remember that XHTML is XHTML unless it is served with a content-type of application/xhtml+xml. – Chris_F May 16 '16 at 21:45