Element.removeAttributeNS() is an instance method that removes a namespaced attribute from an element. Learn MDN’s specialAlign example, SVG xlink:href removal, when to prefer removeAttribute() for plain HTML, pairing with hasAttributeNS(), and five try-it labs aligned with MDN.
01
Kind
Instance method
02
Returns
undefined
03
Args
URI + attrName
04
Missing
no error
05
HTML
removeAttribute
06
Status
Baseline widely
Fundamentals
Introduction
Most HTML attributes are removed with removeAttribute("class"). When an attribute belongs to a namespace — common in SVG and XML — you need removeAttributeNS(namespace, attrName) instead.
MDN: if you work with HTML documents and do not need to specify the attribute as part of a namespace, use removeAttribute(). Reach for removeAttributeNS() when namespace URIs matter.
💡
Beginner tip
MDN names the second parameter attrName. For xlink:href, use namespace http://www.w3.org/1999/xlink and attribute name "href" (local name). Store namespace URIs in constants like XLINK_NS.
Use the XLink namespace URI and attribute name "href". Verify with hasAttributeNS().
📈 Practical Patterns
Plain HTML contrast, verification, and safe no-ops.
Example 3 — Prefer removeAttribute() for HTML
MDN: skip namespaces when deleting ordinary HTML attributes.
JavaScript
const el = document.getElementById("box");
// Namespaced API (only when you need a namespace URI)
// el.removeAttributeNS(SOME_NS, "attrName");
// Simpler for plain HTML (MDN recommendation)
el.removeAttribute("data-role");
console.log(el.hasAttribute("data-role"));
Element.removeAttributeNS() is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.removeAttributeNS()
Remove a namespaced attribute from an element — namespace URI plus attribute name.
BaselineWidely available
Google ChromeSupported · Desktop & Mobile
Yes
Microsoft EdgeSupported · Chromium
Yes
Mozilla FirefoxSupported · Desktop & Mobile
Yes
Apple SafariSupported · macOS & iOS
Yes
OperaSupported · Modern versions
Yes
Internet ExplorerSupported in legacy IE
Yes
removeAttributeNS()Excellent
Bottom line: Use removeAttributeNS() for SVG and XML namespaced attributes. For ordinary HTML attributes, removeAttribute() is simpler (MDN).
Wrap Up
Conclusion
Element.removeAttributeNS() deletes a namespaced attribute from an element. It is the namespace-aware companion to removeAttribute() and pairs naturally with hasAttributeNS() for verification.
Five things to remember about Element.removeAttributeNS()
Namespace-aware attribute removal.
5
Core concepts
📝01
Returns
undefined
API
📄02
Args
URI + name
Two
✍️03
SVG
xlink href
Common
✅04
HTML
removeAttr
Simpler
⚡05
Pair
hasAttrNS
Verify
❓ Frequently Asked Questions
It removes the specified attribute with the specified namespace from an element (MDN).
No. MDN marks Element.removeAttributeNS() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
namespace — a string with the attribute namespace URI. attrName — a string naming the attribute to remove (MDN uses the local name, e.g. specialAlign).
MDN: if you work with HTML and do not need to specify the attribute as part of a namespace, use removeAttribute(attrName) instead.
Nothing useful — the return value is undefined (MDN).
Use hasAttributeNS(namespace, localName) after removing. It should return false when the namespaced attribute is gone.
Did you know?
MDN: for HTML documents where you do not need a namespace, use removeAttribute(). Reach for removeAttributeNS() when the attribute belongs to a specific namespace URI such as XLink in SVG.