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>
  Counter:
  <my-counter></my-counter>
</div>
<p>
  Here's a demo of our experimental "attachEffect". We are now able to attach "side effects" to property value changes, from inside the component and outside.
</p>
<p>
  Check the two calls to "attachEffect" and observe the console log on your dev tools as you click the button.
</p>
<p>Give the project your feedback on <a target="_blank" href="https://ayco.io/gh/web-component-base">GitHub</a></p>
              
            
!

CSS

              
                div {
  font-size: larger;
}
              
            
!

JS

              
                import { WebComponent, attachEffect, html } from "https://unpkg.com/web-component-base@2.0.6/index.js";

class Counter extends WebComponent {
  static props = {
    count: 0,
    sum: 0
  };

  get template() {
    return html`
      <button onClick=${() => ++this.props.count}>
        ${this.props.count}
      </button>
      <button onClick=${() => this.reset()}>reset</button>
    `;
  }

  onInit() {
    attachEffect(this.props.count, (count) => {
      this.getSum(count);
      console.log(
        `(${this.props.sum} * ${count}) from inside`,
        this.props.sum * count
      );
    });
  }

  getSum(x) {
    this.props.sum += x;
  }

  reset() {
    this.props.sum = 0;
    this.props.count = 0;
    console.clear();
  }
}

customElements.define("my-counter", Counter);

// somewhere else, attach effect from outside component
const counter = document.querySelector("my-counter");
attachEffect(counter.props.sum, (sum) =>
  console.log("hello from the other side", sum)
);

              
            
!
999px

Console