Excerpt from the specification:

In HTML documents, you can specify the exact value " http://www.w3.org/1999/xhtml ". This does not apply to XML documents.

Translates roughly: "In HTML documents, elements in the HTML namespace may have an xmlns attribute if it has the exact value" http://www.w3.org/1999/xhtml "."

And then I realized that I did not understand anything at all. I thought that for html there is no concept namespace.

HTML link namespace in the specification leads to the list:

Пространство имён HTML это: http://www.w3.org/1999/xhtml Пространство имён MathML это: http://www.w3.org/1998/Math/MathML Пространство имён SVG это: http://www.w3.org/2000/svg Пространство имён XLink это: http://www.w3.org/1999/xlink Пространство имён XML это: http://www.w3.org/XML/1998/namespace Пространство имён XMLNS: http://www.w3.org/2000/xmlns/ 

And I just can not understand what is meant by the namespace in this specification? The html namespace leads generally to the xhtml specification. And here html5 and xhtml? And how does this relate to the namespace?

What does the phrase "elements in the HTML namespace can have an xmlns attribute"? In the html namespace, where is it? And how does this attribute work in html5?

    1 answer 1

    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

    1. The xmlns attribute in HTML is not needed.
    2. The specification for us defined the namespace names for specific HTML, XML, SVG structures and their elements.
    3. 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.
    • understandably. those. in fact, the namespace in an attribute is no longer a reference, but simply a string (set of characters) that has long been defined? and, in general, it is necessary to select a specific element when the names match, for example, if several languages ​​are used in one document? - Pavel Igorev
    • one
      @PavelIgorev yes, this is a string, and the type of link is chosen to guarantee the uniqueness of this string. And yes, namespaces are needed to delimit elements, when there are several markup in one document. - edem
    • And how does the program understand this or that namespace? Under each namespace there should be some rules hidden so that the program knows which set of rules or instructions to apply. - MaximPro
    • @MaximPro there are no rules, this is a regular line, just a name. - edem pm
    • @edem no I understand that the string is the namespace. But the rules of behavior with a specific namespace should be described. And how will the program understand my namespace? When I even did not provide any special rules. What is the use of these lines if they are just strings? - MaximPro