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="min-h-screen flex items-center justify-center">
  <div class="container flex flex-wrap justify-around">
    <div class="w-1/3 bg-gray-200 border border-gray-400 rounded-xl text-center p-8" x-data="left()">
      <h2 class="text-3xl text-semibold">Component left</h2>
      <p class="text-lg">Write something into the input field and store it into the "store".</p>
      <input type="text" x-model="value" placeholder="Write something..." class="border-2 border-gray-300 rounded-lg w-full text-xl px-4 py-2 my-4" />
      <button type="button" class="text-xl leading-none bg-teal-600 rounded-xl text-white font-bold px-6 py-3 hover:bg-black" @click="store()">STORE</button>

    </div>
    <div class="w-1/3 bg-gray-200 border border-gray-400 rounded-xl text-center p-8" x-data="right()" x-init="init()">
      <h2 class="text-3xl text-semibold">Component right</h2>
      <p class="text-lg">If something is in the store you can fetch it.</p>
      <div class="text-xl font-bold border-2 border-gray-300 rounded-xl px-6 py-3 my-4" x-text="value"></div>
      <button type="button" class="text-xl leading-none bg-teal-600 rounded-lg text-white font-bold  px-6 py-3 hover:bg-black" @click="fetch()">FETCH</button>
    </div>
  </div>
</div>
              
            
!

CSS

              
                .font-sans {
  font-family: Raleway, Helvetica, Arial, sans-serif !important;
}

              
            
!

JS

              
                function left() {
  return {
    value: "",
    store: function () {
      window.store.data.value = this.value;
      window.store.save();
      console.info("Written to the store:", this.value);
    }
  };
}

function right() {
  return {
    value: "Nothing stored...",
    fetch: function () {
      this.value = window.store.data.value;
      console.info("Value fetched from the store:", this.value);
    },
    init: function () {
      this.value = window.store.data.value;
    }
  };
}

window.store = {
  data: {
    value: "Nothing stored..."
  },
  load: function () {
    var storage = localStorage.getItem("alpinejsstore");
    if (storage !== null) {
      this.data = JSON.parse(storage);
    }
  },
  save: function () {
    localStorage.setItem("alpinejsstore", JSON.stringify(this.data));
  }
};

window.store.load();

              
            
!
999px

Console