HTML Guides for xmlns
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
The xmlns attribute declares the XML namespace for an element. For SVG elements, the only permitted namespace is "http://www.w3.org/2000/svg". When this attribute is present but set to an empty string ("") or any value other than the correct namespace, the W3C validator reports an error because the browser cannot properly associate the element with the SVG specification.
In HTML5 documents (served as text/html), the xmlns attribute on <svg> is actually optional. The HTML parser automatically associates <svg> elements with the correct SVG namespace without needing an explicit declaration. However, if you do include the xmlns attribute — for example, because your SVG was exported from a design tool or copied from an XML-based source — it must contain the exact value "http://www.w3.org/2000/svg". An empty or incorrect value will cause a validation error and could lead to rendering issues in certain contexts.
This matters for several reasons:
- Standards compliance: The HTML specification explicitly restricts the allowed value for
xmlnson SVG elements. - Browser compatibility: While most modern browsers are forgiving in HTML mode, an incorrect namespace can cause problems when SVG content is used in XML contexts (such as XHTML or standalone
.svgfiles). - Interoperability: Tools and libraries that process your HTML may rely on the correct namespace to identify and manipulate SVG elements.
To fix this issue, you have two options:
- Set the correct value: Replace the empty or incorrect
xmlnsvalue with"http://www.w3.org/2000/svg". - Remove the attribute entirely: Since
xmlnsis optional in HTML5, simply removing it is often the cleanest solution.
Examples
Incorrect: empty xmlns attribute
This triggers the validation error because the namespace value is an empty string:
<svg xmlns="" width="100" height="100">
<circle cx="50" cy="50" r="40" fill="red" />
</svg>
Incorrect: wrong namespace value
Any value other than the correct SVG namespace will also trigger this error:
<svg xmlns="http://www.w3.org/2000/html" width="100" height="100">
<circle cx="50" cy="50" r="40" fill="red" />
</svg>
Fix: use the correct namespace
Set xmlns to the only permitted value:
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
<circle cx="50" cy="50" r="40" fill="red" />
</svg>
Fix: remove the xmlns attribute
In an HTML5 document, you can omit xmlns altogether since the parser handles the namespace automatically:
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" fill="red" />
</svg>
Note on inline SVG from external sources
Design tools like Figma, Illustrator, or Inkscape often export SVG files with the xmlns attribute already set correctly. If you're copying SVG markup and the xmlns value gets accidentally cleared or corrupted during the process, either restore it to "http://www.w3.org/2000/svg" or remove it before embedding the SVG in your HTML. Both approaches will produce valid, working markup.
The xmlns attribute declares the XML namespace for the document. When present on the <html> element, the HTML specification requires its value to be exactly http://www.w3.org/1999/xhtml — no variations allowed. The URL http://www.w3.org/1999/html is not a recognized namespace and will be rejected by the validator. This error almost always comes from a typo: the "x" before "html" was accidentally omitted.
Why this matters
While most browsers will still render the page in HTML mode regardless of a malformed xmlns value, an incorrect namespace can cause real problems in certain contexts:
- XHTML processing: If the document is served with an XML content type (e.g.,
application/xhtml+xml), an invalid namespace will cause XML parsers to reject or misinterpret the document. - Standards compliance: Validators and automated tools flag this as an error, which can affect quality audits, accessibility checks, and CI/CD pipelines that enforce valid markup.
- Tooling and interoperability: XML-based tools, content management systems, and XSLT transformations rely on correct namespaces to function properly.
How to fix it
You have two options depending on your document type:
- If you need the
xmlnsattribute (e.g., for XHTML or polyglot documents): Change the value fromhttp://www.w3.org/1999/htmltohttp://www.w3.org/1999/xhtml. - If you're writing standard HTML5: Simply remove the
xmlnsattribute. It's optional in HTML5 and has no effect when present with the correct value — so omitting it is the cleanest approach.
Examples
Incorrect — misspelled namespace
The value is missing the "x" before "html":
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html" lang="en">
<head>
<title>My Page</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
Fixed — correct XHTML namespace
Add the missing "x" so the value reads xhtml:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>My Page</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
Fixed — standard HTML5 without xmlns
If you don't need XHTML compatibility, remove the attribute altogether:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Page</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
For most modern websites served as text/html, the third option — omitting xmlns entirely — is the simplest and recommended approach. Only include it if your document must also be valid XHTML or will be processed by XML tooling, and always ensure the value is exactly http://www.w3.org/1999/xhtml.
The xmlns attribute declares the XML namespace for a document. The value http://www.w3.org/TR/REC-html40 is a URL that points to the old HTML 4.0 Recommendation specification — it was never a proper XML namespace identifier. It likely ended up in code through confusion between DTD/specification URLs and actual namespace URIs, or by copying markup from outdated templates.
In the HTML5 specification (the WHATWG HTML Living Standard), the xmlns attribute on the <html> element is optional. When present, its value must be exactly http://www.w3.org/1999/xhtml — no other value is permitted. This is true regardless of whether the document is served as text/html or application/xhtml+xml.
Why this matters
- Validation failure: The W3C validator will reject the document because the namespace value is not one of the allowed values.
- Standards compliance: Using an incorrect namespace can cause XML parsers to misinterpret or reject the document, especially when served with an XML content type.
- Legacy confusion: The
http://www.w3.org/TR/REC-html40URL is a specification reference, not a namespace. Namespaces and specification URLs serve fundamentally different purposes in web standards.
How to fix it
The simplest fix for a standard HTML5 document is to remove the xmlns attribute entirely. The HTML parser does not require it, and browsers will process the document correctly without it.
If your document is served as XHTML (application/xhtml+xml), or if you have a specific reason to include the namespace declaration, update the value to the only permitted one: http://www.w3.org/1999/xhtml.
Examples
❌ Incorrect: old HTML 4.0 URL used as namespace
<!DOCTYPE html>
<html xmlns="http://www.w3.org/TR/REC-html40" lang="en">
<head>
<title>My Page</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
✅ Fix option 1: remove the xmlns attribute (recommended for HTML5)
For most HTML5 documents served as text/html, simply omit the attribute:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Page</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
✅ Fix option 2: use the correct namespace value
If you need the xmlns attribute (e.g., for XHTML serialization), set it to the only allowed value:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>My Page</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
Other incorrect values to watch for
This same error can appear with other invalid namespace URLs. All of the following are wrong:
http://www.w3.org/TR/REC-html40(HTML 4.0 spec URL)http://www.w3.org/TR/html4/(another HTML 4 spec URL)http://www.w3.org/1999/html(non-existent namespace)
The only valid value is http://www.w3.org/1999/xhtml. When in doubt, remove the xmlns attribute altogether — modern HTML5 documents don't need it.
Namespace URIs in XML (and by extension in HTML) are identifiers, not actual URLs that a browser fetches. The W3C and WHATWG specifications define http://www.w3.org/1998/Math/MathML as the one and only valid namespace for MathML. Even though http:// and https:// point to the same server in practice, they are different strings — and namespace matching is purely a string comparison. Using https://www.w3.org/1998/Math/MathML creates what the spec considers an entirely different (and unrecognized) namespace.
This is a common mistake because modern best practices encourage using https:// for everything on the web. However, these namespace URIs were standardized long before HTTPS became the norm, and changing them would break backward compatibility across the entire XML ecosystem. The spec is explicit: only http://www.w3.org/1998/Math/MathML is permitted.
How to Fix It
You have two options depending on your document type:
HTML5 (recommended): Simply remove the
xmlnsattribute from the<math>element. The HTML5 parser recognizes<math>and automatically places it in the correct MathML namespace. No explicit declaration is needed.XHTML or XML documents: If you're serving your document as
application/xhtml+xmlor working in an XML context where explicit namespaces are required, use the exact URIhttp://www.w3.org/1998/Math/MathMLwithhttp://.
The same rule applies to other well-known namespaces like SVG (http://www.w3.org/2000/svg) and XHTML (http://www.w3.org/1999/xhtml) — always use the http:// form specified in the standard.
Examples
Invalid: using https:// in the namespace URI
The https:// scheme causes the validation error:
<math xmlns="https://www.w3.org/1998/Math/MathML">
<mi>x</mi><mo>+</mo><mn>1</mn>
</math>
Fixed: omit xmlns in HTML5
In an HTML5 document, the parser handles the namespace automatically, so the cleanest fix is to drop xmlns altogether:
<!DOCTYPE html>
<html lang="en">
<head>
<title>MathML Example</title>
</head>
<body>
<math>
<mi>x</mi><mo>+</mo><mn>1</mn>
</math>
</body>
</html>
Fixed: use the correct http:// URI
If you need to explicitly declare the namespace (for example, in XHTML served as XML), use the exact http:// URI:
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>x</mi><mo>+</mo><mn>1</mn>
</math>
Quick comparison
| Code | Valid? |
|---|---|
<math xmlns="https://www.w3.org/1998/Math/MathML"> | ❌ Wrong scheme |
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ✅ Correct URI |
<math> (in HTML5) | ✅ Namespace implied |
The xmlns attribute has the XHTML namespace written with https://, but the only allowed value is http://www.w3.org/1999/xhtml.
A namespace name looks like a web address, yet no browser ever loads it. Parsers treat it as a fixed name and compare it character by character, so https://www.w3.org/1999/xhtml names a different namespace than the HTML one. The https usually slips in when a site moves to HTTPS. A search and replace across the templates, or a plugin that upgrades every http:// string, changes the namespace along with the real links. The SVG and MathML namespaces keep http:// too.
In a page served as text/html, the parser puts every element in the HTML namespace by itself, and the HTML standard says xmlns has no effect there, which is why the page still renders. The value matters once the same markup is parsed as XML, for example when it's served as application/xhtml+xml or run through XSLT. Its elements then land in an unknown namespace, and browsers and XML tools no longer treat them as HTML.
Change https back to http. In a page served as HTML you can delete the attribute instead, and keep it only if the same file also has to work as XHTML. If an HTTPS rewrite caused the change, exclude namespace names from it so the next run doesn't break them again.
Invalid example
<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Products</title>
</head>
<body>
<p>Our product range.</p>
</body>
</html>
Valid example
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Products</title>
</head>
<body>
<p>Our product range.</p>
</body>
</html>
XML namespaces are identified by URI strings that act as unique names. They are never fetched or loaded by the browser — they simply serve as an identifier that must match exactly what the specification defines. The XLink namespace has been defined as http://www.w3.org/1999/xlink since its inception, and changing the protocol to https creates a completely different string that parsers and validators do not recognize.
It's a common and understandable mistake. Developers are trained to prefer https:// URLs everywhere for security, and many linting tools or habits may encourage automatically converting http:// to https://. However, namespace URIs are a special case where this rule does not apply. The string is purely declarative — no network request is made, and no security benefit comes from using https.
It's also worth noting that the xmlns:xlink attribute is largely obsolete in modern HTML. When SVG is embedded directly in an HTML5 document, browsers automatically handle namespace resolution. You only need xmlns:xlink when serving SVG as standalone XML (with an .svg file or application/xhtml+xml content type). In most cases, you can simply remove the attribute altogether and use xlink:href or, even better, the plain href attribute, which is now supported on SVG elements like <use>, <image>, and <a>.
Examples
Incorrect: using https:// in the namespace URI
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink">
<use xlink:href="#icon-star"></use>
</svg>
This triggers the validation error because https://www.w3.org/1999/xlink does not match the required namespace identifier.
Fixed: using the correct http:// namespace URI
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<use xlink:href="#icon-star"></use>
</svg>
Preferred: removing the namespace and using plain href
In HTML5, you can drop the xmlns:xlink declaration entirely and use the standard href attribute instead of xlink:href:
<svg xmlns="http://www.w3.org/2000/svg">
<use href="#icon-star"></use>
</svg>
This is the cleanest approach for inline SVG in modern HTML documents. The xlink:href attribute is deprecated in SVG 2, and all modern browsers support plain href on SVG linking elements.
An XML namespace URI is a unique identifier, not an actual web address that your browser fetches. The SVG namespace was defined as http://www.w3.org/2000/svg in the original SVG specification, and that exact string is what HTML parsers and validators expect. Even though using https everywhere is a best practice for real network requests, namespace URIs are not network requests — they are simply fixed strings used to identify which XML vocabulary an element belongs to.
When you write https://www.w3.org/2000/svg instead of http://www.w3.org/2000/svg, the validator sees an unrecognized namespace. This can also cause problems in certain XML-based contexts (such as XHTML or standalone SVG files), where the browser may fail to recognize the element as SVG at all, resulting in your graphics not rendering. In standard HTML5 mode, most browsers will still render inline SVGs correctly regardless of the xmlns value, but the markup is technically invalid and may cause issues in stricter parsing environments like XML serializers, server-side renderers, or tools that process SVG as XML.
This mistake is especially common because many developers reflexively change http to https — or their editor or linter automatically does — when they see a URL-like string. The same principle applies to other namespace URIs like http://www.w3.org/1999/xhtml for HTML and http://www.w3.org/1998/Math/MathML for MathML. These are all fixed identifiers that must not be altered.
How to Fix It
Replace https:// with http:// in the xmlns attribute value. That's it — no other changes are needed.
If your project uses automated tooling that rewrites http URLs to https, you may need to configure an exception for XML namespace URIs.
Examples
❌ Incorrect: Using https in the namespace URI
<svg xmlns="https://www.w3.org/2000/svg" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="40" fill="blue" />
</svg>
This triggers the validation error because https://www.w3.org/2000/svg is not a recognized namespace value.
✅ Correct: Using http in the namespace URI
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="40" fill="blue" />
</svg>
✅ Correct: Inline SVG in HTML without xmlns
When embedding SVG directly inside an HTML5 document, the xmlns attribute is optional — the HTML parser automatically assigns the correct namespace to <svg> elements:
<svg viewBox="0 0 100 100">
<circle cx="50" cy="50" r="40" fill="blue" />
</svg>
This is perfectly valid HTML5. You only need the xmlns attribute when the SVG is served as a standalone .svg file or used within an XHTML document.
The xmlns:xlink attribute on inline SVG accepts only one value, http://www.w3.org/1999/xlink.
The message calls the attribute xmlns:link, but the one to look for in your markup is xmlns:xlink. It declares the XLink namespace, which SVG 1.1 used for attributes such as xlink:href. A namespace URI is a fixed name that the browser never loads, so it has to match the specification character for character. A different year, a trailing slash, https instead of http, or a path segment rewritten by a build tool or a search and replace all trigger this error.
In an HTML document you don't need the declaration at all. The HTML parser puts xlink:href and the other xlink: attributes in the XLink namespace by itself, and SVG 2 lets you write plain href on <use>, <image> and <a>. Either correct the value or remove the attribute and switch xlink:href to href.
Invalid example
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/2000/xlink" viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#icon-star"></use>
</svg>
Valid example
Correct the namespace URI:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#icon-star"></use>
</svg>
Or drop the declaration and use href:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<use href="#icon-star"></use>
</svg>
On <svg> and the elements inside it, the xmlns attribute can only hold the SVG namespace, http://www.w3.org/2000/svg.
When the HTML parser reads inline SVG, it places <svg> and its descendants in the SVG namespace by itself, whatever xmlns says. The main exception is content inside <foreignObject>, which is parsed as HTML. Because the attribute can't change the namespace, the HTML standard makes any other value a parse error, whether it sits on the <svg> element or on a child such as <g> or <path>. A trailing slash or the XHTML namespace triggers it just like an unrelated URI does.
Design tools are a common source. Adobe Illustrator can export a <metadata> block holding an <sfw> element declared in its own Save for Web namespace, http://ns.adobe.com/SaveForWeb/1.0/. In a standalone .svg file, which is parsed as XML, that declaration puts <sfw> in Adobe's namespace. Pasted into HTML, the declaration has no effect and <sfw> becomes an unknown SVG element, so the validator also reports sfw and slices as unknown elements. Browsers don't render <metadata>, so deleting the block leaves the graphic unchanged, and SVG optimizers such as SVGO remove it by default.
For the attribute itself, either set it to exactly http://www.w3.org/2000/svg or remove it, because inline SVG in HTML doesn't need it.
Invalid example
<svg viewBox="0 0 24 24" width="24" height="24">
<metadata>
<sfw xmlns="http://ns.adobe.com/SaveForWeb/1.0/">
<slices></slices>
</sfw>
</metadata>
<circle cx="12" cy="12" r="10" fill="teal"/>
</svg>
Valid example
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<circle cx="12" cy="12" r="10" fill="teal"/>
</svg>
Validate at scale.
Ship accessible websites, faster.
Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.
1K Weekly
1,000 monthly checks. Cancel anytime.
Get 1K Weekly →Join teams across 40+ countries