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



Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO


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.


Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:


Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO


                <!DOCTYPE html>
	<title>Demo - light parallax scroll</title>
	<script type="text/javascript" src=""></script>
	<script type="text/javascript" src="light-parallax-scroll-1.0.js"></script>
	<link rel="shortcut icon" href="/icons/icon-48x48.png"/>
	<link rel="stylesheet" type="text/css" href="">

	<section class="outer-wrapper">
			<section class="top background">
					<h2 class="prlx-down message">And God said let there be Parallax scrolling <br />
					and it was lightweight</h2>
					<div class="hero-image prlx-up">
						<img src=""> <!-- god -->
				<section class="middle background">
					<h2 class="prlx-down message">Both the message and hero image scroll at different speeds and in different directions</h2>
					<div class="hero-image prlx-up-spin">
						<img src=""> <!-- ball -->
				<section class="bottom background">
					<h2 class="prlx-up message">The background images just use css <br />
					background-attachment: fixed;</h2>
					<div class="hero-image prlx-down-right"> 
						<img src=""> <!-- diver -->


                body {
  background: #262626 url(;

.outer-wrapper {
  width: 100%;
  max-width: 1450px;
  margin: auto;

.prlx-down, .prlx-up, .prlx-down-right, .prlx-up-spin{
  position: relative;
section.background 	{
  background-attachment: fixed;
  background-size: cover;
  height: 450px;
  width: 100%;
  overflow: hidden;
} {
  background-image: url(; /* sky */
section.background.middle {
  background-image: url(; /* pitch */
section.background.bottom {
  background-image: url(; /* underwater */

.message {
  display: inline-block;
  background: #fff;
  color: #333;	
  font-size: 18px;
  line-height: 26px;
  font-family: sans-serif;
  text-align: center;
  max-width: 360px;		
  padding: 15px;
  border-radius: 5px;
} .message{
  left: 50%;
  top: 200px;
} .hero-image{
  left: 20%;
  top: 60px;

section.background.middle .message{
  left: 10%;
  top: 100px;
section.background.middle .hero-image{
  left: 70%;
  top: 125px;

section.background.bottom .message{
  left: 10%;
  top: 200px;
section.background.bottom .hero-image{
  left: 50%;
  top: -230px;


                $(document).ready(function () {    
  // cache jQuery selectors to which the parallax animations will occur
  var prlxDown = $('.prlx-down');
  var prlxUp = $('.prlx-up');
  var prlxDownRight = $('.prlx-down-right');
  var prlxUpSpin = $('.prlx-up-spin');
  // set the parallax value vars used for setting setting the speed and direction, 
  // it is calculated in the getYOffsetValue() function with the position of the Y scroll position.
  // A positive value moves the element down the page or infront of the x axis, 
  // while a negative value moves it up the page or behind the x axis.
  var prlxDownValue = .55;
  var prlxUpValue = -.25;
  var prlxUpSpinValue = .35;
  var prlxDownRightValue = .45;
  // declare the vars which will be used to hold the css transform property values in the parallax() function.
  var prlxDownStr;
  var prlxUpStr;
  var prlxUpSpinStr;
  var prlxDownRightStr;
  // set a variable flag which will be used to check weather to run the animations or not.
  var requesting = false;
  // Use the debounce() function to kill the animations 100 milliseconds after the last scroll event using the requesting flag.
  var killRequesting = debounce(function () {
      requesting = false;
  }, 100);

  window.addEventListener("scroll", onScroll, false); // Start the parallax animations on the scroll event by calling the onScroll function.

  function onScroll() {
      if (!requesting) {  // checks to see that the requesting flag is false before running the animations.
          requesting = true;
          requestAnimationFrame(parallax);  // using requestAnimationFrame browser API to perfomr cheaper animations
  function parallax() {  // animations drawn on the page by changeing the css transform properties
      // prlxDown
      prlxDownStr = "translate3d(0, " + getYOffsetValue(prlxDownValue) + "px, 0)";  // putting the transform property into a string
      $(prlxDown).css({  // applying parallax effect to element  

      // prlxUp
      prlxUpStr = "translate3d(0, " + getYOffsetValue(prlxUpValue) + "px, 0)";

      // prlxUpSpin
      prlxUpSpinStr = "rotate(" + getYOffsetValue(prlxUpSpinValue) + "deg) translate3d(0, " + getYOffsetValue(prlxUpValue) + "px, 0)";

      // prlxDownRight
      prlxDownRightStr = "translate3d(" + getYOffsetValue(prlxDownRightValue) + "px, " + getYOffsetValue(prlxDownValue) + "px, 0)";

      function getYOffsetValue(prlxValue) {
          // setting the speed/Value ation effect to be a multiple of the windows Y scroll position
          return ( window.pageYOffset * prlxValue ).toFixed(2)

      if (requesting) {  // check the flag before calling itself again

  // First a browser polyfill... 
  // requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
  // MIT license
  (function () {
      var lastTime = 0;
      var vendors = ['ms', 'moz', 'webkit', 'o'];
      for ( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
          window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
          window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
              || window[vendors[x]+'CancelRequestAnimationFrame'];

      if (!window.requestAnimationFrame)
          window.requestAnimationFrame = function(callback, element) {
              var currTime = new Date().getTime();
              var timeToCall = Math.max(0, 16 - (currTime - lastTime));
              var id = window.setTimeout(function() { callback(currTime + timeToCall); },
              lastTime = currTime + timeToCall;
              return id;

      if (!window.cancelAnimationFrame)
          window.cancelAnimationFrame = function(id) {

  // debounce is taken from _underscore.js
  function debounce(func, wait, immediate) {
      var timeout, args, context, timestamp, result;
      return function() {
          context = this;
          args = arguments;
          timestamp = new Date();
          var later = function() {
              var last = (new Date()) - timestamp;
              if (last < wait) {
                  timeout = setTimeout(later, wait - last);
              } else {
                  timeout = null;
                  if (!immediate) result = func.apply(context, args);
          var callNow = immediate && !timeout;
          if (!timeout) {
              timeout = setTimeout(later, wait);
          if (callNow) result = func.apply(context, args);
          return result;

Two CSS properties walk into a bar. A barstool in a completely different bar falls over.