Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since November 2015.
The HTMLStyleElement.disabled property can be used to get and set whether the stylesheet is disabled (true) or not (false).
Note that there is no corresponding disabled attribute on the HTML <style> element.
Returns true if the stylesheet is disabled, or there is no associated stylesheet; otherwise false. The value is false by default (if there is an associated stylesheet).
The property can be used to enable or disable an associated stylesheet. Setting the property to true when there is no associated stylesheet has no effect.
This example demonstrates programmatically setting the disabled property on a style that was defined in the HTML using the HTML <style> element. Note that you can also access any/all stylesheets in the document using Document.styleSheets.
The HTML contains an HTML <style> element that makes paragraph elements blue, a paragraph element, and a button that will be used to enabled and disable the style.
The code below gets the style element using its id, and then sets it as disabled. As the style already exists, as it is defined in the SVG, this should succeed.
We then add an event handler for the button that toggles the disabled value and button text.
The result is shown below. Press the button to toggle the disabled property value on the style used for the paragraph text.
This example is very similar to the one above, except that the style is defined programmatically.
The HTML is similar to the previous case, but the definition does not include any default styling.
First we create the new style element on the HTML. This is done by first creating a style element using Document.createElement(), creating and appending a text node with the style definition, and then appending the style element to the document body.
We can then disable the style as shown below. Note that this is the earliest point at which setting the property to true will succeed. Before this point the document did not have an associated style, and so the value defaults to false.
Last of all we add an event handler for the button that toggles the disabled state and button text (this is the same as in the previous example).
The result is shown below. Press the button to toggle the disabled state on the style used for the text.
| HTML # dom-style-disabled |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Apr 27, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.