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 id="vanilla-js-app">
  <section class="todo-list">
      <input placeholder="add on Enter" class="todo-list__input"/>
      <ul class="todo-list__list">
        <li class="todo-item">Add another task<button>╳</button></li>
      </ul>
  </section>
</div>

              
            
!

CSS

              
                
              
            
!

JS

              
                const wrapper = document.querySelector('.todo-list');
const input = document.querySelector('.todo-list__input');
const todoList = document.querySelector('.todo-list__list');
const firstItem = document.querySelector('.todo-item');
const firstItemRemoveButton = firstItem.querySelector('button');

// Let's immediately remember the class of the element that we may need to create and delete
const noTodosItemClassName = 'todo-list__no-todos';

// We'll have to separately describe the logic for the first element on the page
firstItemRemoveButton.onclick = () => removeItem(firstItem);

// task deletion function...
function removeItem(item) {
  item.remove();
  // ...and sometimes we create an element with the text "No tasks" and add it to the page
  if (todoList.children.length === 0) {
    const noTodosItem = document.createElement('div');
    noTodosItem.className = noTodosItemClassName;
    noTodosItem.textContent = 'No tasks';
    todoList.remove();
    wrapper.append(noTodosItem);
  }
}

// describing what to do when Enter is pressed in the input
input.onkeydown = (e) => {
  if (e.key !== 'Enter' || !input.value) return;

  // ...and what to do if there are no tasks in the list
  const noTodosItem = wrapper.getElementsByClassName(noTodosItemClassName);
  if (noTodosItem.length) {
    noTodosItem[0].remove();
    wrapper.append(todoList);
  }

  const newTodo = document.createElement('li');
  newTodo.textContent = input.value + ' ';
  
  const removeButton = document.createElement('button');
  removeButton.textContent = '╳';
  
  // ...and what the "╳" button does for a new task
  removeButton.onclick = () => removeItem(newTodo);
  
  newTodo.append(removeButton);
  todoList.append(newTodo);
  
  // ...and finally, don't forget to clear the data
  input.value = '';
}

              
            
!
999px

Console