Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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 padded">
     <div class="row card col-lg-6 col-md-3">
  <!-- beforebegin -->
     <button class="mybtn btn btn-success btn-lg">
  <!-- afterbegin -->
  This is an example button
  <!-- beforeend -->
</button>
<!-- afterend -->


  <p> Look at the html comments for examples of beforebegin, afterbegin, beforeend in relation to this button</p>
</div>
</div>
<div class="container">
<div class="row card col-lg-6 col-md-6 center">
<p><strong>Enter some text to add, then use the first two buttons below to insert your text after the existing text.</strong></p>

<section>
  <p class="card">This is my text</p>
</section>

<input type="text" placeholder="My text to insert before or after"><br>
<button class="before mybtn btn btn-warning btn-sm padded">Insert before</button>
<button class="after mybtn btn btn-primary btn-sm padded">Insert after</button>
<button class="reset mybtn btn btn-danger btn-sm padded">Reset text</button>
</div>
</div>
              
            
!

CSS

              
                /*
A DOMString representing the position relative to the element; must be one of the following strings:
'beforebegin': Before the element itself.
'afterbegin': Just inside the element, before its first child.
'beforeend': Just inside the element, after its last child.
'afterend': After the element itself.
*/
p {
  text-align: center;
}
.padded {
  margin-top: 10px;
  margin-bottom: 10px;
}
              
            
!

JS

              
                const beforeBtn = document.querySelector('.before');
const afterBtn = document.querySelector('.after');
const resetBtn = document.querySelector('.reset');
const para = document.querySelector('section p');
let initContent = para.textContent;

let textInput = document.querySelector('input');

  resetBtn.addEventListener('click', function() {
    para.textContent = initContent;
    textInput.value = '';
  });

  beforeBtn.addEventListener('click', function() {
    para.insertAdjacentText('afterbegin',textInput.value);
  });

  afterBtn.addEventListener('click', function() {
    para.insertAdjacentText('beforeend',textInput.value);
  });
              
            
!
999px

Console