Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is an xmlns declaration in HTML5 really necessary [duplicate]

Tags:

html

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?

like image 687
SebinNyshkim Avatar asked Jun 25 '15 17:06

SebinNyshkim


2 Answers

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.

like image 151
SiCN Avatar answered Sep 19 '22 11:09

SiCN


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

like image 31
Adam Buchanan Smith Avatar answered Sep 21 '22 11:09

Adam Buchanan Smith