Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

HTML

              
                <body> 
  <div id="todos"></div>
</body>

 <style>

.action-remove {
  cursor: pointer;
  color: red;
}

.action-done {
  cursor: pointer;     
}
   
.done {
  text-decoration: line-through;
}


</style>
<script type="module">

import {html, render} from 'https://unpkg.com/lit-html?module';

// Initial list of todos
let todos = []
todos.push({
    'value': 'First todo',
    'done': false
})

// Single todo item
const todoItem = (item, id) => { 

  let classDone = '';
  item.done ? classDone = 'done' : '';

  return html`
  <li class=${classDone} data-id=${id}>${item.value} 
      <span class="action-remove" @click=${todoRemove}>Remove</span> 
      <span class="action-done" @click=${todoDone}>Done</span>
  </li>`
}

// All todo items
const todoAllItems = () => {
  let items = [];
  for (const i in todos) {
    items.push(todoItem(todos[i], i));
  }
  return html`<ul>${items}</ul>`
}

// Full todo app template
const todoMain = () => html`
  <h3>lit-html todo list</h3><input type="text" @keyup=${todoInput} value="">${todoAllItems()}`

// Render wrapper
function doRender () {
  render(todoMain(), document.getElementById('todos'));  
}

// Remove handler
const todoRemove = {
  handleEvent(e) {
    let id = event.target.parentNode.dataset.id;
    todos.splice(id, 1);
    doRender();
  }
}

// Done handler
const todoDone = {
  handleEvent(e) {
    let id = e.target.parentNode.dataset.id;
    todos[id].done= true;
    doRender();
  }
}

// Input handler
const todoInput = {
  handleEvent(e) {
    if (e.keyCode === 13) {
      todos.push({
        'value' : e.target.value,
        'done' : false
      })
      e.target.value = '';
      doRender();
    }
  }
}

// Render app
doRender();

</script>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console