JavaScript Element removeAttribute() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

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)
CallWhat 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

ParameterDescription
attrNameRequired. String name of the attribute to remove

Return Value

Return ValueDescription
*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);
Try It Yourself

How It Works

  1. Select the element. It starts with disabled set.
  2. Call removeAttribute("disabled"). That attribute is deleted (MDN).
  3. Check with hasAttribute. It returns false.
  4. Other attrs stay. width (and the rest) remain unchanged.

Example 2 — Remove class

Strip the entire class attribute in one call.

JavaScript
const box = document.getElementById("box");
box.removeAttribute("class");

console.log(box.getAttribute("class")); // null
console.log(box.className);             // ""
Try It Yourself

How It Works

  1. Target the element that has a class attribute.
  2. Call removeAttribute("class"). The attribute is gone.
  3. getAttribute("class") returns null.
  4. 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)
Try It Yourself

How It Works

  1. Attribute is absent. title is not on the element.
  2. Call removeAttribute. MDN: no error — quiet no-op.
  3. Script continues. Safe for cleanup without a prior hasAttribute check.
  4. Avoid null. Do not “clear” attrs with setAttribute(name, null) (MDN).

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.

Wide Baseline
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · 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.

Next: removeAttributeNode()

Learn how to remove an Attr node from an element.

removeAttributeNode() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

20 people found this page helpful