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="page-container">

  <button id="count-btn" title="Click me to increment count">Current count: ...</button>

  <button id="clear-count-btn" title="Click me to clear the count data from localStorage">Clear count</button>

  <p id="clear-count-data">Count cleared: ...</p>

  <p>Click the button with a number to see data being added to `localStorage` in action.</p>

  <p>The data in `localStorage` persists until it's manually cleared or removed using the `removeItem` or `clear` methods. Click the count button, reload the page, and see how the data remains persistent.</p>
</div>
              
            
!

CSS

              
                .page-container {
  max-width: 480px;
  padding: 2em;
}

body {
  margin: 0;
}

              
            
!

JS

              
                const countBtn = document.querySelector("#count-btn");
const clearCountBtn = document.querySelector("#clear-count-btn");
const clearCountData = document.querySelector("#clear-count-data");

let count = localStorage.getItem("Button clicks");
let countCleared = localStorage.getItem("Count cleared");

countBtn.textContent = `Current count: ${count ?? 0}`;
clearCountData.textContent = `Count cleared: ${countCleared ?? 0} times`;

countBtn.addEventListener("click", (e) => {
  count++;
  localStorage.setItem("Button clicks", count);
  countBtn.textContent = `Current count: ${count ?? 0}`;
});

clearCountBtn.addEventListener("click", (e) => {
  count = 0;
  countCleared++;
  localStorage.removeItem("Button clicks");
  localStorage.setItem("Count cleared", countCleared);
  clearCountData.textContent = `Count cleared: ${countCleared ?? 0} times`;
  countBtn.textContent = `Current count: ${count}`;
});

              
            
!
999px

Console