What does html xmlns=http://www.w3.org/1999/xhtml do?
You're mixing up HTML with XHTML.
Usually a <!DOCTYPE>
declaration is used to distinguish between versions of HTMLish languages (in this case, HTML or XHTML).
Different markup languages will behave differently. My favorite example is height:100%
. Look at the following in a browser:
XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css">
table { height:100%;background:yellow; }
</style>
</head>
<body>
<table>
<tbody>
<tr><td>How tall is this?</td></tr>
</tbody>
</table>
</body>
</html>
... and compare it to the following: (note the conspicuous lack of a <!DOCTYPE>
declaration)
HTML (quirks mode)
<html>
<head>
<style type="text/css">
table { height:100%;background:yellow; }
</style>
</head>
<body>
<table>
<tbody>
<tr><td>How tall is this?</td></tr>
</tbody>
</table>
</body>
</html>
You'll notice that the height of the table is drastically different, and the only difference between the 2 documents is the type of markup!
That's nice... now, what does <html xmlns="http://www.w3.org/1999/xhtml">
do?
That doesn't answer your question though. Technically, the xmlns
attribute is used by the root element of an XHTML document: (according to Wikipedia)
The root element of an XHTML document must be
html
, and must contain anxmlns
attribute to associate it with the XHTML namespace.
You see, it's important to understand that XHTML isn't HTML but XML - a very different creature. (ok, a kind of different creature) The xmlns
attribute is just one of those things the document needs to be valid XML. Why? Because someone working on the standard said so ;) (you can read more about XML namespaces on Wikipedia but I'm omitting that info 'cause it's not actually relevant to your question!)
But then why is <html xmlns="http://www.w3.org/1999/xhtml">
fixing the CSS?
If structuring your document like so... (as you suggest in your comment)
<html xmlns="http://www.w3.org/1999/xhtml">
<!DOCTYPE html>
<html>
<head>
[...]
... is fixing your document, it leads me to believe that you don't know that much about CSS and HTML (no offense!) and that the truth is that without <html xmlns="http://www.w3.org/1999/xhtml">
it's behaving normally and with <html xmlns="http://www.w3.org/1999/xhtml">
it's not - and you just think it is, because you're used to writing invalid HTML and thus working in quirks mode.
The above example I provided is an example of that same problem; most people think height:100%
should result in the height of the <table>
being the whole window, and that the DOCTYPE
is actually breaking their CSS... but that's not really the case; rather, they just don't understand that they need to add a html, body { height:100%; }
CSS rule to achieve their desired effect.
Does HTML 5 need `html xmlns=http://www.w3.org/1999/xhtml`
No, you don't need to include it. This should be enough.
<!doctype html>
<html>
What does the xmlns attribute do?
From the W3Schools:
the xmlns attribute specifies the xml namespace for a document.
This basically helps to avoid namespace conflicts between different xml documents, if for instance a developer mixes xml documents from different xml applications.
An example of this (also from the W3 website):
XML data to define an html table:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
XML data to define information about a coffee table
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
There are two table elements here, which would produce a conflict. To fix this, you can add a namespace to signify which piece of information defines an html table and which comprises information about a coffee table:
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="http://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
Firefox add a xmlns=http://www.w3.org/1999/xhtml
Your selector represents something that is, or is in an a
tag.
A much more minimal version of your problem would be:
html:
<a id="test"></a>
js:
$('#test').html('<p>test</p>');
result:
<a id="test"><p><a xmlns="http://www.w3.org/1999/xhtml">test</a></p></a>
Change things around so you aren't putting p
tags in an a
tag, or do the following:
$('#test').empty().append('<p>test</p>');
Does xmlns:xlink=http://www.w3.org/1999/xlink still have a function?
xlink namespace is not depricated. See Xml Linking Language specification, but it is optional from HTML5 to include the xmlns
attribute to your HTML page. So if you use HTML5+ you should have no use for that link.
Link to w3
Note: The xmlns attribute is required in XHTML, invalid in HTML 4.01,
and optional in HTML5.Note: The HTML validator at http://w3.org does not complain when the
xmlns attribute is missing in an XHTML document. This is because the
namespace "xmlns=http://www.w3.org/1999/xhtml" is default, and will be
added to the tag even if you do not include it.
Html, xmlns, namespaces, xml
There's quite a lot of confusion evident in your question, and it's not easy to resolve it without writing an entire tutorial on XML namespaces. I'll try cover as best I can how they relate to (X)HTML.
First though, the purpose of namespaces is to separate vocabularies. So, for example, the title
element in the http://www.w3.org/1999/xhtml
namespace can be distinguished from the title
element in the http://www.w3.org/2000/svg
namespace, when they appear in the same document, or processed by a common processor.
Second, forget about the http://www.w3.org/2000/xmlns/
namespace. What it does is largely behind the scenes and you rarely need to worry about it.
Next, we need to distinguish between the null namespace, the default namespace, and namespaces referenced by prefixes.
When an XML file has no xmlns=
attributes defined, all the unprefixed elements are said to be 'in the null namespace', or 'in no namespace' which amounts to the same thing.
When an XML element has an xmlns=
attribute, it and its descendant elements, if they are unprefixed are said to be 'in the default namespace' where the default namespace is the value of the xmlns attribute.
Prefixed elements are always in the namespace mapped by xmlns:prefix=
attributes in the element or ancestor of the element.
Now, the XHTML vocabulary is defined as elements in the http://www.w3.org/1999/xhtml
namespace, so a correctly written XHTML document will declare either that namespace as being the default namespace, or will map a prefix to the namespace, in which case all the XHTML elements will need to include that prefix on their names. (This latter situation doesn't happen very often, for reasons given below).
So, when parsing XHTML with an XML parser, the namespace mapping needs to be there.
However, XPath has no concept of a default namespace. If you don't put the prefix on the elements named in the xpath, it will attempt to match elements in the null namespace. If the XHTML elements are in the http://www.w3.org/1999/xhtml
namespace, then the xpath won't match anything.
This is where it starts to get complicated - browsers.
If you serve XHTML web pages to browsers as you should, with an XML content type like application/xhtml+xml, the browser will use an XML parser to load it and all the above rules apply. If you don't include the xmlns="http://www.w3.org/1999/xhtml"
attribute, browsers won't understand how to process it and will simply display the file as a raw XML structure.
However, because IE until IE9 didn't support XML content-types, hardly anybody does serve their web pages that way. Instead they use the "text/html" content type, in which case the browser doesn't use an XML parser at all, it uses an HTML one.
The HTML parser just ignores the namespace to prefix mappings, and simply "knows" which element names belong in which namespaces. This makes it ultimately less flexible, but within its specialized domain, more robust and simple to use. (In the example of the title
element above, it determines which namespace applies by looking at the title
s ancestor elements) This is why XHTML documents don't use prefixed elements, because an HTML parser won't recognise them.
Browsers, (the modern ones anyway), then have specialized DOM-alike API methods and CSS rules to hide all this namespace complexity away from the javascript and css author, and thus, for the most part, namespacing can be safely ignored by web authors.
Standalone HTML parsers, however, don't always do this. Instead, they place all the elements in the null namespace, which means that they can be found with xpaths that don't include prefixes on the element names, using standard DOM APIs. For most practical purposes, this amounts to the same thing as when browser parse using their HTML parser.
So, in summary, you need to be aware of whether you are parsing your XHTML with an XML or HTML parser, and how that particular parser is assigning elements to namespaces, in order to be able to write a correct xpath to query for elements within the document.
Trying to use Https in an ASP Application, What about html attribute of `xmlns`
Keep the http
: The xmlns
attribute defines the default namespace. The http
in its value is a significant part of this identifier. Changing it to https
would refer to a different namespace not understood by browsers. The same applies to the rest including the 1999
part.
The xmlns
attribute gives an IRI or URI, see XML namespace for details. It is just a convention to use a URL linking to information about the namespace. Typically, newer versions of the underlying specification (here XHTML 1.0) only ever get a new identifier if they are incompatible with previous versions. Even the specification for XHTML 1.1 published in 2010 uses the same namespace identifier (with 1999
in it).
You may also want to have a look at document type declarations typically used with HTML and XHTML and understood by browsers. If both namespace and document type are used they should match.
Related Topics
How to Convert Escape Characters in HTML Tags
Aligning Elements Left, Center and Right in Flexbox
Hide Email Address from Bots - Keep Mailto:
CSS: Responsive Way to Center a Fluid Div (Without Px Width) While Limiting The Maximum Width
Overlaying a Div on Top of HTML 5 Video
Using "Label For" on Radio Buttons
Align Div's to Bottom or Baseline
How to Make a Div Take The Full Width of The Page When It Is Inside Another Div That Have 90% Width
How to Prevent Div Tag Starting a New Line
HTML5 Drag and Drop Images from a Toolbar to a Canvas
CSS: How to Create a Gap Between Rows in a Table
HTML List Isn't Vertically Aligned When Using Floating Images
Why Is The Default Max Length for an Input 524288
Difference Between "Lang" and "Type" Attributes in a Script Tag