Element.removeAttribute() removes the attribute with the given name from the element (MDN). If that attribute is missing, the call does nothing and does not throw. Returns undefined.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call el.removeAttribute. Start with this line.
JavaScript
el.removeAttribute(attrName)
Call
What it does
el.removeAttribute(attrName)
Primary signature.
el.removeAttribute(...)
Call with the arguments your case needs.
Built into the browser. Call removeAttribute(...) on an Element — no import required.
Library declarations
JavaScript
el.removeAttribute(attrName)
Parameters
Parameter
Description
attrName
Required. String name of the attribute to remove
Return Value
Return Value
Description
*
Always undefined
JavaScript Examples
Example 1 — Remove disabled (MDN)
Enable a control by deleting the disabled attribute.
JavaScript
const el = document.getElementById("div1");
el.removeAttribute("disabled");
console.log(el.hasAttribute("disabled")); // false
console.log(el.outerHTML);
Call removeAttribute("class"). The attribute is gone.
getAttribute("class") returns null.
Note: To remove one class token only, use classList.remove instead.
Example 3 — Missing Attribute Is Safe
Calling remove on a name that is not present does not throw.
JavaScript
const el = document.getElementById("box");
el.removeAttribute("title"); // no title → no error (MDN)
console.log("still ok");
// Prefer this over:
// el.setAttribute("title", null); // often wrong (MDN)
Call removeAttribute. MDN: no error — quiet no-op.
Script continues. Safe for cleanup without a prior hasAttribute check.
Avoid null. Do not “clear” attrs with setAttribute(name, null) (MDN).
Compatibility
Browser Support
Element.removeAttribute() is Baseline Widely available on MDN (across browsers since July 2015). Safe for everyday attribute cleanup.
✓ Baseline Widely available
Element.removeAttribute()
Remove an HTML attribute by name — widely supported.
WideBaseline
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
removeAttribute()Widely available
Bottom line: Call el.removeAttribute(name). Prefer over setAttribute(name, null). Missing attributes are a safe no-op.
Frequently Asked Questions
It removes the attribute with the specified name from the element (MDN).
No. MDN marks Element.removeAttribute() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
A string with the name of the attribute to remove, such as "disabled", "class", or "data-id" (MDN).
undefined. There is no return value (MDN).
MDN: removeAttribute() returns without generating an error. It is a safe no-op.
MDN recommends removeAttribute() instead of setting the attribute value to null. Many attributes do not behave as expected when set to null.