Pen Settings



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


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


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.


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.


  <div class="bg"></div>
  <h1>Tweening parallax sections</h1>
  <div class="bg"></div>
  <h1>Hey look, a title</h1>
  <div class="bg"></div>
  <h1>They just keep coming</h1>
  <div class="bg"></div>
  <h1>So smooth though</h1>
  <div class="bg"></div>
  <h1>Nice, right?</h1>


                section {
  position: relative;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;

.bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 200%;
  z-index: -1;
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;

h1 {
  color: white;
  text-shadow: 1px 1px 3px black;
  z-index: 1;
  font-size: 3em;
  font-weight: 400;



                const sections = gsap.utils.toArray("section");
const lastIndex = sections.length - 1;

sections.forEach((section, i) => {
  section._bg = section.querySelector(".bg");
  section._h1 = section.querySelector("h1");
  // Give the backgrounds some random images = `url(${innerWidth}/${innerHeight*2}?random=${i})`;

  // Create a standalone ST instance, and use the progress value (0 - 1) to tween the timeline's progress
    trigger: section,
    start: ()=> i==0 ? "top top" : "top bottom", // The FIRST section will use a different start value than the rest
    end: ()=> i==lastIndex ? "top top" : "bottom top", // The LAST section will use a different start value than the rest    
    onRefresh: self => { // onRefresh (so it gets reset upon resize), create a timeline that moves the h1 + bg vertically      
      section._tl = gsap.timeline({paused:true, defaults:{ease:'none', overwrite:'auto'}}) 
      .fromTo(section._h1, {y:()=> i==0 ? 0 : (innerHeight/2)*1.5}, {y:()=> i==lastIndex ? 0 : (-innerHeight/2)*1.5}, 0)
      .fromTo(section._bg, {y:()=> i==0 ? -innerHeight/2 : 0}, {y:()=> i==lastIndex ? -innerHeight/2 : -innerHeight}, 0)	  
      .progress(self.progress); //use progress to position the timeline correctly      
    onUpdate: self => {, {duration:0.75, progress:self.progress}); }