References

Beginner-friendly references for web development, with live, editable examples.

The HTML xmlns attribute

Attribute All modern browsers Updated
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.
Where do head attributes apply?
On the metadata elements in the <head><meta>, <link>, <script> and <base>.
What is the difference between async and defer?
async runs a script as soon as it loads in no set order; defer runs scripts in order after the document is parsed.
Which elements use the xmlns attribute?
It is an element-specific attribute, used on document head elements like <meta>, <link> and <script>.