Reputation: 7519
If I have a xhtml document, I assume the default namespace is "xhtml". Is there any advantage, or disadvantage, to explicitly declaring this default namespace, as in:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude">
<head>
. . .
Upvotes: 0
Views: 346
Reputation: 82966
In HTML5 compatible browsers the default namespace for HTML elements in the HTML serialization is http://www.w3.org/1999/xhtml
In the XHTML serialization, XML rules apply. If you don't assign a default namespace using xmlns=
, unprefixed elements will be in no namespace, and the browser will not understand how to interpret your markup. In that sense, you need to explicitly declare the default namespace.
However...
Whether you are using the HTML serialization or the XHTML serialization depends not on the DOCTYPE but on the content-type. You only get the XHTML serialization if you serve the page with an XML content type such as application/xhtml+xml
.
If you serve the page with a content type of text/html
(and I'm willing to bet you are, since almost everybody does) then you are using the HTML serialization and your XHTML 1.0 Strict doctype is of no consequence. In that case, the default namespace declaration is achieving nothing except keeping the validator quiet.
Upvotes: 2