HTML Namespace Definitions
Definition: HTML Namespace(s)
(Some links on this page take you to details in the HTML Tag Reference. Bookmark this page in your Favorites so you can come back to it later.)
A namespace is a property associated with the name of some object, such as a node in an HTML document, that distinguishes the type of object represented by the name from other types of objects with the same name in other namespaces. For example, in
<head><title>One Of My Web Pages</title></head>
title
is the name of an element (the title element) in HTML while in
<a href="..." title="One of my links" ...>
title
is the name of a title attribute on an HTML <a> tag.
The HTML namespaces (plural) in general are the collection of various namespaces in HTML code. The HTML namespace (singular) itself is the one associated with the namespace URI http://www.w3.org/1999/xhtml
.
On this site, the notation <a href>
refers to the href
attribute in the html:a
element namespace, where html:
is the namespace prefix for the HTML namespace.
Why are there namespaces in HTML?
Names that are spelled the same and have the same namespace cannot be distinguished from one another without knowing the context in which they appear. For example, in the RSS version 2.0 and OPML version 2.0 code below, the three <title>
elements with the same name in the same namespace partition (the element partition without a namespace URI in this case) all identify the same type of object:
<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"> <channel> <title>Feed Title</title> ... <item> <title>Item Title</title> ... </item> </channel> </rss> <?xml version="1.0" encoding="UTF-8"?> <opml version="1.0"> <head> <title>My OPML</title> </head> <body> ... </body> </opml>
In order to differentiate the title
elements above you would have to know that the first one was a descendant of an rss
element and channel
element; the second was a descendant of an rss
element, channel
element and item
element; and the third was a descendant of an opml
element and a head
element.
In addition, without namespaces there might be elements with the same element name that have different meanings or content depending on where they are used. Their different models would have to be combined to create a single definition (XML Schema definition or DTD) of the element. This might work if all meanings were determined by the same entity, but it would likely be a major issue if different standards bodies or industry groups were involved.
This type of confusion in XML content without namespaces makes it very difficult to aggregate that content into other types of content, even if the other content formats do support namespaces. For example, if portions of the content above was included in an HTML document (without overriding the namespace with xmlns=""
), the title
elements would be treated as a valid HTML titles, the head
element and body
element would be treated as duplicates of their HTML counterparts and most of the other elements would be treated as invalid HTML code.
Note that the HTML title
element would not be confused with the title
elements shown above, since its name is in a different namespace partition associated with the HTML namespace URI.