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.

              @font-family: 'Raleway', "Helvetica Neue", Arial, sans-serif;
  @font-size: 1em;
  @color-dark: #54599c;
  @color-light: #fff;
  @color-light-gray: #d3d3d3;
  @color-light-blue: #e2f5ff;
  @color-error: #ff000e;
  @color-error-light: #fde5ec;
  @link-color: #2196F3;

  button {
    font-family: @font-family;
    font-size: @font-size;

  body {
    background-color: @color-dark;
    padding: 5%;

  form {
    background-color: @color-light;
    padding: 30px 40px 0 40px;
    border-radius: 6px;


  input {
    border: 1px solid @color-light-gray;
    border-radius: 4px;
    padding: 3%;
    margin-bottom: 20px;

    &:not([type=checkbox]) {
      width: 93%;

    &:focus {
      background-color: @color-light-blue;
      outline: 0;
      border-color: #a1c7e8;

  button {
    background-color: #3ec967;
    text-transform: uppercase;
    letter-spacing: 2px;
    border-radius: 20px;
    border: 0;
    color: White;
    padding: 10px;
    width: 100%;

  a {
    color: @link-color;

  h2 {
    color: #b027a1;
    text-align: center;
    font-size: 2em;

  aside {
    background-color: #f1f0ff;
    margin: 40px -40px;
    padding: 15px;
    border-radius: 0px 0px 6px 6px;
    text-align: center;
    color: @color-dark;

  .welcome-message {
    color: white;
    text-align: center;

  .error {
    padding: 20px;
    margin-top: 20px;
    text-align: center;
    color: @color-error;
    background-color: @color-error-light;

  todo-list {
    display: flex;
    flex-direction: column;
    align-items: center;
              import {
  } from "//";


  const Session = DefineMap.extend('Session', {});
  Session.connection = [
  ].reduce((conn, behavior) => behavior(conn), {
    Map: Session,
    url: {
      resource: '/api/session',
      getData: '/api/session',
      destroyData: '/api/session',

  const Todo = DefineMap.extend('Todo', {
    body: 'string',
    completed: 'boolean'
  Todo.connection = restModel({
    Map: Todo,
    url: '/api/todo'

  class TodoLogin extends StacheElement {
    static view = `
      {{# if (this.Session.currentPromise.isResolved) }}
        <p class="welcome-message">
           Welcome {{ }}.
           <a href="javascript://" on:click="this.logOut()">Log out</a>
      {{/ if }}

      {{# if (this.Session.currentPromise.isPending) }}
        Loading User...
      {{/ if }}

      {{# if (this.Session.currentPromise.isRejected) }}
        <form on:submit="this.logIn(scope.event)">
          <h2>Log In</h2>

          <input placeholder="email" value:to="" />

          <input type="password" placeholder="password"
                 value:to="this.password" />

          <button>Log In</button>

          {{# if (this.logInError) }}
            <div class="error">{{ this.logInError.message }}</div>
          {{/ if }}

             Login with the following account details:<br/>
             Password: abc123<br/>
      {{/ if }}

    static props = {
      email: String,
      password: String,
      logInError: type.Any,

    get Session() {
      return Session;

    logOut() {

    logIn(event) {
      this.logInError = null;

      const session = new Session({
        password: this.password
      }); => {
        this.logInError = error;
  customElements.define("todo-login", TodoLogin);

  class TodoList extends StacheElement {
    static view = `
      {{#each (this.todos)}}
          <input type="checkbox" checked:bind="this.completed" />
          {{ this.body }}

    static props = {
      todos: {
        async(resolve) {
          Session.currentPromise.then(() => {
          return [];
  customElements.define("todo-list", TodoList);

  function setupFixtures() {
    fixture("GET /api/session", function (request, response) {
      const session = getSession();

      if (session) {
      } else {
        response(404, {message: "No session"}, {}, "unauthorized");

    fixture("POST /api/session", function (request, response) {
      const email =;
      const password =;

      if (
        email === '' &&
        password === 'abc123'
      ) {
        document.cookie = `SESSION-TOKEN=${btoa(JSON.stringify({email, password}))}`;
      } else {
        response(401, {message: "Unauthorized"}, {}, "unauthorized");

    fixture("DELETE /api/session", function () {
      document.cookie = 'SESSION-TOKEN=';
      return {};

    fixture("GET /api/todo", function () {
      const session = getSession();

      if (session) {
        return todos;
      } else {
        response(401, {message: "Unauthorized"}, {}, "unauthorized");

  // get browser cookies as a map from key to value
  function getCookieMap() {
    return document.cookie.split(';').map(cookie => cookie.split('=')).reduce((map, [key, value]) => {
      map[key] = value;
      return map;
    }, {});

  // get the decoded session cookie
  function getSession() {
    try {
      const token = getCookieMap()['SESSION-TOKEN'];
      // a real backend would verify the token by checking a database or by decrypting the token
      return JSON.parse(atob(token));
    } catch (e) {
      return null;

  const todos = [
    {body: 'buy milk', completed: true},
    {body: 'pick up dry cleaning', completed: false},
    {body: 'call mom', completed: false},
    {body: 'clean basement', completed: false},
🕑 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.