coderef

execCommand()Limited availability

The document.execCommand() method reads and writes from the clipboard and performs editing commands on editable text, such as changing the font name or style. Related methods check whether commands are supported, enabled, or applied.

Not yet supported in all major browsers — check the table and provide a fallback.

Discouraged: 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." Use instead: Async clipboard, contenteditable

Browser support

DesktopChrome
1+Supportedsince Dec 11, 2008
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1–68Not supported
69+Supportedsince Sep 3, 2019
Current: 157
Safari
1–1.2Not supported
1.3+Supportedsince Apr 15, 2005
Current: 27
MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155
Firefox Android
4–68Not supported
79+Supportedsince Jul 28, 2020
Current: 157
Safari iOS
1+Supportedsince Jun 29, 2007
Current: 27

How to use

Support is still inconsistent across browsers. Use feature detection and test carefully.

Example

Full syntax and examples are on MDN: execCommand.

Feature detection

JS · check before using
if ("Document" in globalThis && "execCommand" in Document.prototype) {
  // Document.execCommand is available
}

Sub-features

Support for each part of the feature (10). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Document.execCommand112691.318791
Document.execCommand.copy42126910427910
Document.execCommand.cut42126910427910
Document.execCommand.defaultParagraphSeparator✕✕69✕✕79✕
Document.execCommand.insertBrOnReturn✕✕69✕✕79✕
Document.queryCommandEnabled11269218791
Document.queryCommandIndeterm11269218791
Document.queryCommandState11269218791
Document.queryCommandSupported11269218791
Document.queryCommandValue11269218791