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. It matters when serving XHTML (XML), and on inline <svg>/<math> roots where the correct namespace makes the content render.
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.