English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM execCommand() Method

HTML DOM Document Object

execCommand()The method is to execute a command on the current document, current selection, or specified range.

When the HTML document has switched todesignModeits document object will use the execCommand method to run the command for the current editable area.

Most commands affect the document selection (bold, italic, etc.), while other commands insert new elements (add links) or affect the entire line (indent).

UseWhen contentEditable is, the execCommand() affects the currently active editable element.

Syntax:

document.execCommand(commandName, showDefaultUI, valueArgument)
document.execCommand("bold");
Test and see‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the execCommand() method:

Method
execCommand()Is4129109

Parameter Value

ParameterDescription
commandNameA string that specifies the name of the command to be executed.
Here is a list of possible commands:
"backColor"
           "bold"
           "createLink"
           "copy"
           "cut"
           "defaultParagraphSeparator"
           "delete"
           "fontName"
           "fontSize"
           "foreColor"
           "formatBlock"
           "forwardDelete"
           "insertHorizontalRule"
           "insertHTML"
           "insertImage"
           "insertLineBreak"
           "insertOrderedList"
           "insertParagraph"
           "insertText"
           "insertUnorderedList"
           "justifyCenter"
           "justifyFull"
           "justifyLeft"
           "justifyRight"
           "outdent"
           "paste"
           "redo"
           "selectAll"
           "strikethrough"
           "styleWithCss"
           "superscript"
           "undo"
           "unlink"
           "useCSS"
showDefaultUIA boolean value indicating whether the default user interface should be displayed
valueArgumentFor commands that require input parameters, it is the string that provides this information. For example, insertImage requires the URL of the image to be inserted.

Technical Details

Return Value:A boolean value, false if the command is not supported or disabled

More Examples

Change the fontSize of the selected text:

document.execCommand("fontSize", false, 7);
Test and see‹/›

You can also check out

DOM Document:designModeProperties

DOM Element:contentEditableProperties

HTML DOM Document Object