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


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


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.


                <div id="todos">
  <form method="post" action="/my-backend-script">
    <input type="text" placeholder="What's next?" />
    <input type="submit" value="Add" />
    <li>Item n.1</li>
    <li>Item n.2</li>



                #todos {
  font-family: sans-serif;
  color: #444;

 * Todo List Input
#todos form {
  display: flex;

#todos form input[type="text"],
#todos form input[type="submit"] {
  padding: 5px 10px;
  border: 1px solid #666;
  outline: none;

#todos form input[type="text"] {
  flex: 1;

#todos form input[type="text"]:focus {
  border-color: #369;

#todos form input[type="submit"] {
  display: none;
  text-transform: uppercase;

#todos form input[type="submit"]:active {
  border-color: #369;
  background-color: #369;
  color: #fff;

By adding a simple "is-valid" class to the
Todo's FORM - that wraps all the other
components - then we can easily fix the
style to display a "ready to sent" UI.

It's Javascript that implements the logic
to add or remove the "is-valid" class.
#todos input[type="submit"] {
  display: block;

#todos input[type="text"] {
  margin-right: 10px;

 * Todos List

#todos ul {
  margin: 10px 0 0 0;
  padding: 0;
  border: 1px solid #ddd;
  border-radius: 4px;

#todos ul li {
  padding: 5px 10px;
  border-bottom: 1px solid #ddd;
  transition: background-color 500ms ease;

#todos ul li:last-child {
  border-bottom: none;

#todos ul li:hover {
  background-color: #cde;



In order to make things a little easier, I've imported a few
utility functions from previous exercises, and adapted to
the Todo List DOM structure.

I've also set up the event listener that will hide and show
the "ADD" button based on the message status.

You are welcome :-)

With this setup, you can focus on appending the new item
to the list.

- what is a good event to use?
- do you still need to validate the message?

 * Utility Functions

const getTodosForm = () =>
    .querySelector('#todos form')

const getTodosInput = () =>
    .querySelector('#todos input[type="text"]')

const getTodosList = () =>
    .querySelector('#todos ul')

const getMessage = () =>

const messageIsValid = text =>
  text.length > 0

const cancelEvent = (event) => {

const resetTodosInput = () => {
  const input = getTodosInput()
  input.value = ''

 * App's Logic

const checkStatus = () => {
  const classList = getTodosForm().classList
  const message = getMessage()

    ? classList.add('is-valid')
    : classList.remove('is-valid')

// Setup the chat status listener
const inputEl = getTodosInput()
inputEl.addEventListener('input', checkStatus)
inputEl.addEventListener('change', checkStatus)

// Setup the submit handler and figure out how to
// validate the action and add the item to the list