The HTML xmlns attribute
Quick answer
The HTML xmlns attribute declares the XML namespace of the document. It is used on the <html> element (and SVG/MathML roots).
Overview
The xmlns attribute declares the XML namespace of the document. It applies to the <html> element (and SVG/MathML roots).
In ordinary HTML it is unnecessary; the HTML namespace is implied, and the parser gives inline <svg>/<math> roots their namespace automatically. It matters when the document is served as XML (XHTML or a standalone SVG file), where the correct namespace is what makes the content render; on inline roots it is kept as a portability habit.
Syntax
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
Values
| Value |
|---|
A namespace URI: for HTML, http://www.w3.org/1999/xhtml. |
Best practices
- Declare the character encoding with <meta charset="utf-8"> first in the <head>.
- Load scripts with defer (or as modules) so they do not block parsing.
- Protect third-party resources with integrity and crossorigin (Subresource Integrity).
- Use resource hints like preload deliberately, paired with the right as value.
Frequently asked questions
What does the xmlns attribute do?
Declares an XML namespace.
Where do head attributes apply?
What is the difference between async and defer?
Which elements use the xmlns attribute?
It is an element-specific attribute, used on the
<html> element (and SVG/MathML roots).