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.

              <div id="container"></div>
<div id="nav">
  <a id="link-a" href="#">AAAAA</a>
  <a id="link-b" href="#">BBBBB</a>
  <a id="link-c" href="#">CCCCC</a>
<div id="a" class="box">
  <h1>View A</h1>
  <p>In this example each view is managed in an array. The order in the array matches the order of the buttons at the top. The transition between views is determined by the position of the new view in the array relative to current view. If the view is to the left, for example the new view is A, and current view is B. The transition slides left to right. </p>
<div id="b" class="box">
  <h1>View B</h1>
<div id="c" class="box">
  <h1>View C</h1>
              body, html {
  margin: 0;
  height: 100%;

#container {
  width: 100%;
  height: 100%;
  background: lightgray;
  position: relative;

#nav {
  position: fixed;
  left: 20px;
  top: 20px;

#link-a, #link-b, #link-c {
  display: inline-block;
  padding: 1em;
  color: white;
  background: black;

.box {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 60px 2em 0 2em;
  position: absolute;
  border: 3px solid red;

#a {
  background: cyan;

#b {
  background: yellow;

#c {
  background: magenta;

              // Define some view elements to work with
var a = $("#a");
var b = $("#b");
var c = $("#c");

// Add an array to hold the views
var viewsArray = [a, b, c];

// Remove these views from the DOM

// This var will hold a reference to the current view
var currentView;

// Define some transitions 
  var offLeft = {
    left: "-100%"
  var onHorizontal = {
    left: 0

  var offRight = {
    left: "100%"
  var offDown = {
    top: "100%"
  var offUp = {
    top: "-100%"
  var onVertical = {
    top: 0
  // These combinations create transitions in four directions
  // Slide right: offRight, offLeft, onHorizontal
  // Slide left: offLeft, offRight, onHorizontal
  // Slide down: offDown, offUp, onVertical
  // Slide up: offUp, offDown, onVertical

// Some helper functions to create transitions in four directions
function pushLeft(newView) {
  showView(newView, offRight, offLeft, onHorizontal)

function pushRight(newView) {
  showView(newView, offLeft, offRight, onHorizontal)

function pushDown(newView) {
  showView(newView, offDown, offUp, onVertical);

function pushUp(newView) {
  showView(newView, offUp, offDown, onVertical);

function showView(newView, exit, start, enter) {
  // Hide Current View
  if (currentView) {
    currentView.animate(exit, 400, function() {
  // Show New View
  currentView = newView;
  currentView.css(start).animate(enter, 400, function() {


function showViewInArray(newView) {
  // Don't load the current view again
  if (currentView == newView) {
  // Find the index of the current view
  var indexOfCurrentView = viewsArray.indexOf(currentView);
  // Find the index of the new view
  var indexOfNewView = viewsArray.indexOf(newView);
  if (indexOfCurrentView == -1) {
    // There is no current, so do a pushLeft
  } else {
    if (indexOfNewView < indexOfCurrentView) {
      // The new view is to the left in the array
    } else {
      // The new view is to the right in the array

// These functions make use of the new transition helper functions
$("#link-a").click(function(event) {

$("#link-b").click(function(event) {

$("#link-c").click(function(event) {
🕑 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.