| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/Document/queryCommandState | [Back] [Original] |
Get to know MDN better
Avoid using this feature in new projects.
The execCommand() method is "not implemented consistently or fully by user agents, and it is not expected that this will change in the foreseeable future."
This feature may be a candidate for removal from web standards or browsers.
Consider using the following features instead: Async clipboard or contenteditable.
Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
Note:
Although the execCommand() method is deprecated, there are still some valid use cases that do not yet have viable alternatives, as mentioned in the execCommand() article. In these cases, you may find this method useful to implement a complete user experience, but test to ensure cross-browser compatibility.
The queryCommandState() method will tell you if the current selection has a certain Document.execCommand() command applied.
queryCommandState(command)
commandA command from Document.execCommand()
queryCommandState() can return a boolean value or null if the state is unknown.
<div contenteditable="true">Select a part of this text!</div>
<button>Test the state of the 'bold' command</button>
<hr />
<div id="output"></div>
hr,
button {
margin: 1rem 0;
}
function makeBold() {
const state = document.queryCommandState("bold");
let message;
switch (state) {
case true:
message = "The bold formatting will be removed from the selected text.";
break;
case false:
message = "The selected text will be displayed in bold.";
break;
default:
message = "The state of the 'bold' command is indeterminable.";
break;
}
document.querySelector("#output").textContent = `Output: ${message}`;
document.execCommand("bold");
}
document.querySelector("button").addEventListener("click", makeBold);
This feature is not part of any current specification. It is no longer on track to become a standard. There is an unofficial W3C execCommand spec draft.
HTMLElement.contentEditabledocument.designModedocument.execCommand()queryCommandState(): Scribe's "Browser Inconsistencies" documentationThis page was last modified on Aug 21, 2026 by MDN contributors.
DocumentactiveElementactiveViewTransitionadoptedStyleSheetsalinkColorallanchorsappletsbgColorbodycharacterSetchildElementCountchildrencompatModecontentTypecookiecurrentScriptcustomElementRegistrydefaultViewdesignModedirdoctypedocumentElementdocumentURIdomainembedsfeaturePolicyfgColorfirstElementChildfontsformsfragmentDirectivefullscreenfullscreenElementfullscreenEnabledheadhiddenimagesimplementationlastElementChildlastModifiedlastStyleSheetSetlinkColorlinkslocationpictureInPictureElementpictureInPictureEnabledpluginspointerLockElementpreferredStyleSheetSetprerenderingreadyStatereferrerrootElementscriptsscrollingElementselectedStyleSheetSetstyleSheetsstyleSheetSetstimelinetitleURLvisibilityStatevlinkColorxmlEncodingxmlVersionadoptNode()append()ariaNotify()browsingTopics()caretPositionFromPoint()caretRangeFromPoint()clear()close()createAttribute()createAttributeNS()createCDATASection()createComment()createDocumentFragment()createElement()createElementNS()createEvent()createExpression()createNodeIterator()createNSResolver()createProcessingInstruction()createRange()createTextNode()createTouch()createTouchList()createTreeWalker()elementFromPoint()elementsFromPoint()enableStyleSheetsForSet()evaluate()execCommand()exitFullscreen()exitPictureInPicture()exitPointerLock()getAnimations()getElementById()getElementsByClassName()getElementsByName()getElementsByTagName()getElementsByTagNameNS()getSelection()hasFocus()hasPrivateToken()hasRedemptionRecord()hasStorageAccess()hasUnpartitionedCookieAccess()importNode()moveBefore()mozSetImageElement()open()prepend()queryCommandEnabled()queryCommandState()queryCommandSupported()querySelector()querySelectorAll()releaseCapture()replaceChildren()requestStorageAccess()requestStorageAccessFor()startViewTransition()write()writeln()AbortControllerAbortSignalAbstractRangeAttrCDATASectionCharacterDataCommentCustomEventDOMErrorDOMExceptionDOMImplementationDOMParserDOMTokenListDocumentFragmentDocumentTypeElementEventEventTargetHTMLCollectionMutationObserverMutationRecordNamedNodeMapNodeNodeIteratorNodeListProcessingInstructionQuotaExceededErrorRangeShadowRootStaticRangeTextTreeWalkerXMLDocumentXPathEvaluatorXPathExpressionXPathResultXSLTProcessorYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |