Pro attribute xmlns
Concerning xmlns, in the same text , immediately after the quotation given in the question, the following is said:
Note: In HTML, the xmlns attribute has absolutely no effect. It is basically a talisman. XHTML is mildly easier.
Note: In HTML, the xmlns attribute has no effect. This is just a talisman. It only makes it easier to convert to and from XHTML documents.
With this sorted out, xmlns in HTML, we do not need. Of course, it can be used for HTML elements, but it does not make sense, since for all structures in the HTML document there are already predefined values of the "namespace", the list of which is given in the question, and nobody will allow changing them to other values. Simply put, the following examples are equivalent:
<html xmlns="http://www.w3.org/1999/xhtml"> <html>
But this way <html xmlns="что-то своё"> no longer possible, since xmlns is simply ignored, and html will still be located in the namespace " http://www.w3.org/1999/xhtml " it was said above.
About namespace
By analogy with the names of classes, packages, etc. from programming languages, the namespace allows to distinguish one element from another, when they have the same name, but belong to different namespaces. Where can this happen in HTML? For example, when we use svg in html:
<svg> <a xlink:href="/"><text x="0" y="20" fill="green">Ссылка в SVG</text></a> </svg> <a href="/">Ссылка в HTML</a>
And we needed to change the font size of the link in svg. Just writing in a { font-size: 1.5em } no longer possible, since this rule will also apply to a regular link, too. This is where CSS features for working with namespaces come to the rescue. To do this, CSS will perform the following actions:
1) Using the keyword @namespace we specify the name of the "prefix" of the namespace, with which we will deal:
@namespace svg url(http://www.w3.org/2000/svg);
Note: the namespace address for SVG is taken from the specification, and instead of svg you can use another name.
2) Now, using the svg prefix, you can directly access the <a> , which is located in <svg></svg> , using the special CSS syntax:
svg|a { font-size: 1.5em; }
Total
- The xmlns attribute in HTML is not needed.
- The specification for us defined the namespace names for specific HTML, XML, SVG structures and their elements.
- In order for CSS to access a specific element using a namespace, you must use the
namespace|css-selector form namespace|css-selector , first giving the name to the namespace using @namespace.