## HTML `xmlns` Attribute
The `xmlns` attribute specifies the XML namespace for an HTML or XHTML document. It is used to identify the vocabulary of the elements and attributes within the document, preventing naming conflicts when different XML dialects are mixed.
---
## Definition and Usage
* **In XHTML:** The `xmlns` attribute is **required**. It defines the default XML namespace for the document.
* **In HTML5 / HTML:** The `xmlns` attribute is **optional** and has no real effect. Modern browsers automatically parse HTML5 documents using the standard HTML namespace, even if the attribute is omitted.
### Why is it used?
The value `http://www.w3.org/1999/xhtml` points to the official W3C XHTML namespace. Even if you omit this attribute in an XHTML document, the W3C HTML validator will still validate the document correctly because `"xmlns=http://www.w3.org/1999/xhtml"` is the default namespace and is automatically assumed for the `` tag.
---
## Browser Support
| Attribute | Chrome | Edge/IE | Firefox | Safari | Opera |
| :--- | :--- | :--- | :--- | :--- | :--- |
| **`xmlns`** | Yes | Yes | Yes | Yes | Yes |
All major modern web browsers support the `xmlns` attribute.
---
## Syntax
```html
```
### Attribute Values
| Value | Description |
| :--- | :--- |
| `http://www.w3.org/1999/xhtml` | Specifies the default XML namespace for XHTML documents. |
---
## Code Examples
### Example 1: A Minimal XHTML Document
This is a basic, valid XHTML document containing the minimum required tags and the `xmlns` attribute.
```html
Document Title
This is a valid XHTML document utilizing the xmlns attribute.
```
### Example 2: Mixing Namespaces (SVG inside HTML5)
In modern HTML5, you can embed other XML-based languages like SVG or MathML. While HTML5 parses these automatically, specifying the namespace explicitly can be useful for XML parsers.
```html
Embedded SVG Namespace Example
Inline SVG
```
---
## Key Considerations
1. **HTML5 vs. XHTML:** If you are writing standard modern HTML5 (``), you do not need to include `xmlns="http://www.w3.org/1999/xhtml"`. It is only strictly necessary if you are serving your pages as XML with the `application/xhtml+xml` MIME type.
2. **Case Sensitivity:** In XHTML, all element and attribute names (including `xmlns`) must be written in lowercase.
3. **Self-Closing Tags:** When using the `xmlns` attribute in XHTML, ensure that all empty elements (like ``, ` `, and ``) are properly self-closed (e.g., ``).