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
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
if ("Document" in globalThis && "execCommand" in Document.prototype) {
// Document.execCommand is available
}Documentation (MDN)
Specification
Usage share
Sub-features
Support for each part of the feature (10). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| Document.execCommand | 1 | 12 | 69 | 1.3 | 18 | 79 | 1 |
| Document.execCommand.copy | 42 | 12 | 69 | 10 | 42 | 79 | 10 |
| Document.execCommand.cut | 42 | 12 | 69 | 10 | 42 | 79 | 10 |
| Document.execCommand.defaultParagraphSeparator | ✕ | ✕ | 69 | ✕ | ✕ | 79 | ✕ |
| Document.execCommand.insertBrOnReturn | ✕ | ✕ | 69 | ✕ | ✕ | 79 | ✕ |
| Document.queryCommandEnabled | 1 | 12 | 69 | 2 | 18 | 79 | 1 |
| Document.queryCommandIndeterm | 1 | 12 | 69 | 2 | 18 | 79 | 1 |
| Document.queryCommandState | 1 | 12 | 69 | 2 | 18 | 79 | 1 |
| Document.queryCommandSupported | 1 | 12 | 69 | 2 | 18 | 79 | 1 |
| Document.queryCommandValue | 1 | 12 | 69 | 2 | 18 | 79 | 1 |