HTML DOM Document execCommand() method

Definition and usage

execCommand() The method is deprecated. Do not use it.

The applet attribute returns empty in all new browsers HTMLCollection.

HTML5 does not support the <applet> element.

Alternative:

Document designMode attribute

Element contentEditable attribute

Example

To make the selected text bold:

document.execCommand("bold");

Try it yourself

Syntax

document.execCommand(command, showUI, value)

Parameters

Parameters Description
command

The name of the command to be executed:

  • "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"
  • "subscript"
  • "superscript"
  • "undo"
  • "unlink"
  • "useCSS"
showUI Boolean value. Specifies whether the UI should be displayed.
value Some commands require a value to be completed.

Return value

Type Description
Boolean value If the command is supported, it is true; otherwise, it is false.