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="app" class="container">
   
   <!-- Components -->
   <div class="row">
      <h4>Components</h4>
      <!-- Props kebob-case in HTML-->
      <my-component comp-label="Label Title"></my-component>
      <my-component comp-label="Another Label"></my-component>
      <my-component></my-component>
   </div>
   
   <!-- Template -->
   <template id="textComponent">      
      <strong>{{compLabel}}</strong>
      <p>This text stays the same!</p>
   </template>
   
   

   <!-- Form Input Bindings -->
   <div class="row">
      <h4>Form Input Bindings <small>v-model</small></h4>
      <span>Message is: {{ message }}</span>
      <br />
      <input type="text" class="u-full-width" v-model="message" lazy placeholder="Edit me... I'm in lazy mode">
      <br />
      <label for="checkbox">
         <input type="checkbox" id="checkbox" v-model="checked"> {{ checked }}
      </label>
      <br />
      <label for="jack">
         <input type="checkbox" id="jack" value="Jack" v-model="checkedNames"> Jack
      </label>
      <label for="john">
         <input type="checkbox" id="john" value="John" v-model="checkedNames"> John
      </label>
      <label for="mike">
         <input type="checkbox" id="mike" value="Mike" v-model="checkedNames"> Mike
      </label>
      <br>
      <span>Checked names: {{ checkedNames | json }}</span>
      <br />

      <label for="one">
         <input type="radio" id="one" value="One" v-model="picked"> One
      </label>
      <br>
      <label for="two">
         <input type="radio" id="two" value="Two" v-model="picked"> Two
      </label>
      <br>
      <span>Picked: {{ picked }}</span>
      <br />
      <select class="u-full-width" v-model="selected">
         <option selected>Choose One...</option>
         <option v-for="option in options" v-bind:value="option.value">
            {{ option.text }}
         </option>
      </select>
      <span>Selected: {{ selected }}</span>
   </div>


   <!-- Events/Methods -->
   <div class="row">
      <h4>Events/Methods</h4>
      <button v-on:click="greet">Greet</button>
      <button v-on:click="say('hi', $event)">Say Hi</button>
      <button type="submit" v-on:click="say('hello!', $event)">Submit</button>
      <input type="text" v-on:keyup.enter="say('Submitted', $event)" placeholder="Press Enter">
   </div>


   <!-- List Rendering -->
   <div class="row">
      <h4>List Rendering</h4>
      <ul>
         <li v-for="item in items">
            {{ parentMessage }} - {{ $index }} - {{ item.message }}
         </li>
      </ul>
   </div>
   <!-- Spcecify Alias for $index in a template -->
   <ul class="list-unstyled">
      <template v-for="(index, item) of items">
       <li>{{ index }} {{ item.message }}</li>
       <li class="divider"></li>
     </template>
   </ul>


   <!-- Conditional -->
   <div class="row">
      <h4>Conditionals <small>v-if/v-else</small></h4>
      <h5 v-if="ok">Yes</h5>
      <h5 v-else>No</h5>
   </div>
   <template v-if="ok">
      <h1>Title</h1>
      <p>Paragraph 1</p>
      <p>Paragraph 2</p>
   </template>
   <p>NOTE: Generally speaking, v-if has higher toggle costs while v-show has higher initial render costs. So prefer v-show if you need to toggle something very often, and prefer v-if if the condition is unlikely to change at runtime.</p>


   <!-- HTML Class Bindings -->
   <div class="row">
      <h4>Class/Style Bindings</h4>
      <p class="text-center" :class="{ 'class-a': classA }">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut iusto quo recusandae sed sapiente molestiae consequatur itaque rerum eos facilis, molestias ex ipsam commodi omnis, nisi exercitationem facere blanditiis modi!</p>
   </div>


   <!-- Computed Properties -->
   <div class="row">
      <h4>Computed Properties</h4>
      <p>a = {{ a }}, b = {{ double }}</p>
      <input type="number" class="u-full-width" v-model="a" placeholder="Enter a number">
      <hr />
      <h5>Hello<span v-if="firstName || lastName"> {{ fullName }}</span></h5>
      <div class="row">
         <div class="six columns">
            <input type="text" class="u-full-width" v-model="firstName" placeholder="Enter a First Name">
         </div>
         <div class="six columns">
            <input type="text" class="u-full-width" v-model="lastName" placeholder="Enter a Last Name Name">
         </div>
      </div>
   </div>


   <!-- Basic Binding with v-model -->
   <div class="row">
      <h4>Hello {{ message }}</h4>
      <label class="u-full-width">Username:</label>
      <input type="text" class="u-full-width" v-model="message" placeholder="Enter a username">
   </div>


   <!-- Data -->
   <div class="row">
      <pre><code>{{ $data | json }}</code></pre>
   </div>
   <!-- closes #app -->
</div>
              
            
!

CSS

              
                body {
   font-family: 'Lato', sans-serif;
   padding-top: 3em;
}


/* Skeleton Overrides */

h1,
h2,
h3,
h4,
h5,
h6 {
   letter-spacing: initial;
}
label, legend { display: inline; }
.row + .row {
   border-top: 1px solid #ddd;
   padding-top: 1em;
   margin-top: 3em;
}
small {
   color: #999;
   font-size: 65%;
}


/* Extra Styles */

.text-center { text-align: center; }
.class-a { color: blue; }
.list-unstyled {
   padding-left: 0;
   list-style: none;
}
.divider {
   height: 1px;
   margin: 9px 0;
   overflow: hidden;
   background-color: #e5e5e5;
}
              
            
!

JS

              
                // extend and register in one step
Vue.component('my-component', {
   //Props camelCase in JS
   props: {
    compLabel: {default:  'Default Label'}
  },
   template: '#textComponent',
   data: function() {
     return { }
   }
})

new Vue({
   el: '#app',
   data: {
      message: '',
      a: 11,
      firstName: 'Bob',
      lastName: 'Smith',
      fullName: '',
      classA: true,
      ok: true,
      parentMessage: 'Parent Message',
      items: [
         { message: 'Foo' },
         { message: 'Bar' }
       ],
      checked: 'true',
      checkedNames: [],
      picked: '',
      selected: 'A',
       options: [
         { text: 'One', value: 'A' },
         { text: 'Two', value: 'B' },
         { text: 'Three', value: 'C' }
       ]
   },
   computed: {
      double: function() {
         return this.a * 2
      },
      fullName: function() {
         return this.firstName + ' ' + this.lastName
      }
   },
   // define methods under the `methods` object
  methods: {
    greet: function (event) {
      // `this` inside methods point to the Vue instance
      alert('Hello ' + this.fullName + '!' + 'This is fired by ' + event.target.tagName)
    },
    say: function (msg, event) {
       event.preventDefault()
       alert(msg)
    }
  }
});
              
            
!
999px

Console