Formatting
suggest changeUsers can add formatting to contenteditable documents or elements using their browser’s features, such as common keyboard shortcuts for formatting (Ctrl-B for bold, Ctrl-I for italic, etc.) or by dragging and dropping images, links, or markup from the clipboard.
document.execCommand is deprecated and browser-only. It changes the current selection, so a call with no selection does nothing useful. Ctrl-B is a Windows and Linux shortcut. macOS uses Cmd-B.
document.execCommand('bold', false, null); // toggles bold formatting
document.execCommand('italic', false, null); // toggles italic formatting
document.execCommand('underline', false, null); // toggles underline
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents