This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The removeAttribute() method of the Sanitizer interface sets an attribute to be disallowed on all elements.
The specified attribute is added to the list of removeAttributes in this sanitizer's configuration. The attribute is removed from the attributes list if present.
Note that to allow/disallow attributes only on specific elements use Sanitizer.allowElement().
removeAttribute(attribute)
attributeA string indicating the name of the attribute to be disallowed globally on elements, or an object with the following properties:
nameA string containing the name of the attribute.
namespace OptionalA string containing the namespace of the attribute, which defaults to null.
None (undefined).
This example shows how removeAttribute() is used to specify that an attribute is should be removed from elements.
The code first creates a new Sanitizer object that initially specifies no attributes or elements. We then call removeAttribute() with the attributes title and mathcolor.
// Create sanitizer that allows
const sanitizer = new Sanitizer({
removeAttributes: [],
});
// Remove the title attribute
sanitizer.removeAttribute("title");
// Remove the mathcolor attribute
sanitizer.removeAttribute("mathcolor");
// Log the sanitizer configuration
let sanitizerConfig = sanitizer.get();
log(JSON.stringify(sanitizerConfig, null, 2));
The final configuration is logged below. Note how both attributes are now added to the removeAttributes list (these attributes will removed if present on elements when the sanitizer is used).
| Specification |
|---|
| HTML Sanitizer API> # dom-sanitizer-removeattribute> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
removeAttribute |
No | No | 138 | No | No | No | No | No | No | No | No | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Sanitizer/removeAttribute