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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <templiteral-intro greeting="world" buttonMessage="Click me"></templiteral-intro>
              body {
  --accent: rebeccapurple;
  --primary: #121212;
  --radius: 4px;
  --white: #ffffff;
              /** NOTE: This example assumes you are using a modern browser */
import { Component } from 'https://unpkg.com/templiteral/dist/templiteral.es.min.js';

const introStyles = new CSSStyleSheet();
class TempliteralIntro extends Component {
  static get boundAttributes() {
    return ['greeting', 'buttonMessage'];
  constructor() {
    this.attachShadow({ mode: 'open' });
    this.state = {
      greeting: this.getAttribute('greeting') || '',
      bindDemoMessage: 'Try me out',
      reasons: [
        'It\'s easy',
        'It\'s future-friendly',
        'No third-party dependencies',
        'Fully standards compliant',
        'It\'s platform agnostic (it will work with Angular, React or whatever)',
        'No complicated build-step'
      buttonMessage: 'Click me'
    this.shadowRoot.adoptedStyleSheets = [introStyles];
  alertUser() {
    const buttonMessages = ['OK, stop, that tickles', 'Click me'];
    if (this.state.buttonMessage === buttonMessages[1]) {
      this.state.buttonMessage = buttonMessages[0];
    } else {
      this.state.buttonMessage = buttonMessages[1];
  render() {
    <h1>Hello ${this.state.greeting}!</h1>

    ${this.if(this.state.greeting === 'you')`<p>Yeah, ${this.state.greeting}!</p>`}

    <p>I am <a href="https://www.npmjs.com/package/templiteral" target="_blank" rel="noopener noreferrer">templiteral</a>, a light-weight in-browser template engine for managing data, property and event bindings in <code>customElements</code>.</p>

    <p>Some reasons to try templiteral:</p>

      ${this.state.reasons.map((reason, index) => this.fragment(index)`

    <p>See the source on <a href="https://github.com/calebdwilliams/templiteral" target="_blank" rel="noopener">GitHub</a>.</p>

    <bind-demo [message]="${this.state.bindDemoMessage}"></bind-demo>

    <p>In the JS pane above, you can tinker with some of the features of templiteral. Here I've added an input that will change the greeting.</p>

    <label for="greeting">New greeting</label>
    <input type="text" name="greeting" id="greeting" (input)="${event => this.state.greeting = event.target.value}" ref="input" placeholder="Change greeting">

    <button (click)="${this.alertUser}">${this.state.buttonMessage}</button>

  :host {
    background: var(--white);
    display: block;
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
  h1, h2, p { color: var(--primary); }
  p, li { line-height: 150%;}
  * { font-family: Helvetica, Arial, sans-serif; } 
  a { color: var(--accent); }
  a:visited { color: var(--accent); }
  label { 
    display: block; 
    font-weight: 700; 
    margin-top: 1rem; 
  input {
    border: 0;
    border-radius: var(--radius);
    box-shadow: 0 0 1px var(--primary);
    font-size: 1rem;
    margin-top: 0.5rem;
    padding: 0.5rem;
  button {
    background: var(--accent);
    border: 0;
    border-radius: var(--radius);
    color: var(--white);
    font-size: 1rem;
    padding: 0.55rem 1rem;
  code {
    background: #193549;
    border-radius: var(--radius);
    color: #ffc600;
    font-family: "Operator Mono", "Fira Code", "Consolas", "Courier New", monospace;
    padding: 0px 4px;

customElements.define('templiteral-intro', TempliteralIntro);

class BindDemo extends Component {
  static get boundAttributes() {
    return ['message'];
  render() {

customElements.define('bind-demo', BindDemo);

function changeIntroGreeting() {
  const el = document.querySelector('templiteral-intro');
  const greetings = [el.greeting, 'everyone', 'you'];
  let index = 0;
  el.addEventListener('addGreeting', event => console.log(event));
  setInterval(() => {
    if (!el.root.querySelector('#greeting').value) {
      el.setAttribute('greeting', greetings[index]);
      index === (greetings.length - 1) ? index = 0 : index += 1;
  }, 3000);


🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.