Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <h1>More Fun With execCommand</h1>
  <p>Try it out by selecting some text in the paragraph below and the buttons:</p>
  
  <p contenteditable="true" spellcheck="false" class="box">
     Phasellus semper magna ac interdum scelerisque. Vestibulum laoreet sapien a nisi ullamcorper, nec luctus neque eleifend. Aliquam vel tortor justo. Nam aliquam dapibus mi ut volutpat. Donec eros turpis, gravida et neque nec, interdum pulvinar nibh. Ut vel sodales nulla, a tempus sem. Nunc facilisis pretium aliquam. Proin nulla ante, congue at purus sit amet, commodo placerat erat. Sed malesuada eros nulla, in cursus urna elementum finibus. Suspendisse posuere purus pellentesque rutrum tempor. Nunc nec tincidunt est. Sed convallis ligula quis dui laoreet maximus. Nulla pharetra placerat quam ut rutrum. Nullam sit amet vehicula nisi.
  </p>
  
  <p class="text-center">
    <button id="bold-btn">Bold</button>
    <button id="italic-btn">Italic</button>
    <button id="underline-btn">Underline</button>
    <button id="strike-through-btn">StrikeThrough</button>
  </p>

  <p class="text-center">
    <button id="supscript-btn">Supscript</button>
    <button id="superscript-btn">Superscript</button>
  </p>
  
   <p class="text-center">
    <button id="color-btn">Color</button>
    <button id="size-btn">Size</button>
    <button id="delete-btn">Delete</button>
    <button id="undo-btn">Undo</button>
    <button id="redo-btn">Redo</button>
  </p>
</div>

              
            
!

CSS

              
                .box {
  border: 1px solid #aaa;
  border-radius: 4px;
  padding: 15px;
}

.text-center {
  text-align: center;
}
              
            
!

JS

              
                document.addEventListener("DOMContentLoaded", () => {
  const $ = document.querySelector.bind(document);
  const boldBtn = $("#bold-btn"),
        italicBtn = $("#italic-btn"),
        underlineBtn = $("#underline-btn"),
        strikeThroughBtn = $("#strike-through-btn"),
        subscriptBtn = $("#supscript-btn"),
        superscriptBtn = $("#superscript-btn"),
        colorBtn = $("#color-btn"),
        sizeBtn = $("#size-btn"),
        deleteBtn = $("#delete-btn"),
        undoBtn = $("#undo-btn"),
        redoBtn = $("#redo-btn");
  
  boldBtn.addEventListener("click", () => {
    document.execCommand('bold');
  });
  
  italicBtn.addEventListener("click", () => {
    document.execCommand('italic');
  });
  
  underlineBtn.addEventListener("click", () => {
    document.execCommand('underline');
  });
  
  strikeThroughBtn.addEventListener("click", () => {
    document.execCommand('strikeThrough');
  });
  
  subscriptBtn.addEventListener("click", () => {
    document.execCommand('subscript');
  });
  
  superscriptBtn.addEventListener("click", () => {
    document.execCommand('superscript');
  });
  
  colorBtn.addEventListener("click", () => {
    document.execCommand('styleWithCSS', false, true);
    document.execCommand('foreColor', false, 'hotpink');
  });
  
  sizeBtn.addEventListener("click", () => {
    document.execCommand('styleWithCSS', false, true);
    document.execCommand('fontSize', false, '25px');
  });
  
  deleteBtn.addEventListener("click", () => {
    document.execCommand('delete');
  });
  
  undoBtn.addEventListener("click", () => {
    document.execCommand('undo');
  });
  
  redoBtn.addEventListener("click", () => {
    document.execCommand('redo');
  });
});

// https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
              
            
!
999px

Console