Pen Settings



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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


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


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.


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.



  The below table is a different element from the above component, but it can read its state too. This does not used centralized/shared state, either.

    <th>Current state</th>
    <th>New (incoming) state</th>
    <th>Previous (outgoing) state</th>
    <td>Clicks: <code data-print-state>0</code></td>
    <td>Clicks: <code data-print-newState>null</code></td>
    <td>Clicks: <code data-print-prevState>null</code></td>




                class Component {
  constructor(element) {
    this.element = element;

    this.state = new Proxy({ }, {
      set: (store, state, value) => {
        const prevState = {};
        prevState[state] = store[state];
        const newState = {};
        newState[state] = value;

        if(store[state] !== value) {
          store[state] = value;

          this.element.dispatchEvent(new CustomEvent("state-change", {
            detail: {
              context: this.element,
              newState: newState,
              prevState: prevState,

        return true;

    let debouncedSync = null;
    let stateBatch = {};

    this.element.addEventListener("state-change", (event) => {
      stateBatch.newState = { ...stateBatch.newState, ...event.detail.newState };
      stateBatch.prevState = { ...stateBatch.prevState, ...event.detail.prevState };

      if(debouncedSync) {

      debouncedSync = window.requestAnimationFrame(() => {
        this.sync(stateBatch.newState, stateBatch.prevState);
        stateBatch = {};
  sync(newState, prevState) {
    console.warn("No local sync method provided in component subclass.");

class Counter extends Component {
  constructor(element) {
    this.state.count = 0;
    this.element.addEventListener("click", () => {
  sync(newState, prevState) {
    if("count" in newState) {
      this.element.textContent = `Clicks: ${this.state.count}`;

const myCounter = new Counter(document.querySelector("button"));

const curStateCell = document.querySelector("[data-print-state]");
const newStateCell = document.querySelector("[data-print-newState]");
const prevStateCell = document.querySelector("[data-print-prevState]");

myCounter.element.addEventListener("state-change", (event) => {
  curStateCell.textContent = myCounter.state.count;
  newStateCell.textContent = event.detail.newState.count;
  prevStateCell.textContent = event.detail.prevState.count;