+ 1

Html xmlns attribute

What is the xmlns attribute for when specified within the html tag? How is it being actually used by the system?

24th Apr 2020, 8:31 AM
ifl
ifl - avatar
3 Answers
+ 7
Just like using <!doctype HTML> to declare HTML5 document, **xmlns** is used to declare XHTML( A stricter version of HTML, said to be a combination of XML and HTML) with strict rules such has **everything must be in lowercase, indented etc**
24th Apr 2020, 10:12 AM
Mirielle
Mirielle - avatar
+ 2
XHTML is *an application of* XML and it has a corresponding "XML schema" (XSD)* that tells you which tags are allowed inside an XHTML document, also which attributes those tags have. The XSD for XHTML requires an XML namespace (xmlns) for the outer <html> tag, as is customary in XML based languages. HTML on the other hand is not an application of XML, rather it's based on SGML, and it does not require an xmlns. You might recognize <svg> tags inside your XHTML as special, inside of <svg> you can put tags that aren't allowed anywhere else in the document, and vice versa. And in fact if you create svg elements in javascript you have to specify a namespace (c.f. document.createElementNS). The uri you put inside xmlns doesn't have to exist, it just needs to be unique, but usually you will point it to a schema definition (I have not tried not doing that). [1/2] __ * Technically not an XSD but a document type definition (DTD) I think, it's complicated, historical reasons yada yada
24th Apr 2020, 10:22 AM
Schindlabua
Schindlabua - avatar
+ 1
How do namespaces work? Typically in XHTML we use only unqualified namespaces, like so <html xmlns="http://w3.org/1999/xhtml"> <body> <p></p> <svg xmlns="http://w3.org/2000/svg"> <text /> </svg> </body> </html> but I believe you should also be able to define prefixed namespaces, like so <html xmlns="http://w3.org/1999/xhtml" xmlns:grafix="http://w3.org/2000/svg" > <body> <p></p> <grafix:svg> <grafix:text /> </grafix:svg> </body> </html> But nobody does that. A common example of namespaced XML usage is XSLT, a different application of XML. [2/2]
24th Apr 2020, 10:28 AM
Schindlabua
Schindlabua - avatar