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 class="overlay"></div>
<div class="content">iOS Safari Bug</div>
              
            
!

CSS

              
                body {
  font-family: sans-serif;
}
* {
  box-sizing: border-box;
}
body, html {
  margin: 0;
  padding: 0;
  scroll-behavior: auto;
  transition: none;
}

.overlay {
  position: fixed;
  height: 100vh;
  padding: 20px;
  color: red;
}
.content {
  height: 800vh;
  line-height: 100vh;
  font-size: 50px;
  text-align: center;
}
              
            
!

JS

              
                // You MUST run this in /debug/ mode to expose the bug (works fine in iframe). 
// https://codepen.io/GreenSock/debug/16c435b12ef09c38125204818e7b45fc?editors=0010
// iOS misreports scroll position! Set it, check it immediately and it's correct but then 
// on the next requestAnimationFrame (or sometimes in the same one), it REVERTS to the previous scroll position!!!

let increaseLoad = true, // heavier load causes the problem to show up.
		iterations = 50,
		currentScroll = 0,
    isCloseEnough = (v1, v2) => Math.abs(v1 - v2) <= 2; // Safari is often 1 pixel off, so we give it 2 pixels leeway;

// this function just changes the scroll position to a random one, but before it does so, it checks to see if the previous scroll position that was set is still what it was supposed to be (expose the bug)
function changeScroll() {  
  checkScroll(); // make sure it matches what we set previously
  currentScroll = Math.round(Math.random() * 800); // pick a random scroll position
  window.scrollTo(0, currentScroll);  // go there
  if (iterations--) { // only do this for a certain number of iterations
    requestAnimationFrame(changeScroll);
  }
}

// ONLY WORKS IF WE USE ASYNC AND AWAIT TRUE HERE!!!
function checkScroll() {
  if (increaseLoad) { // just chews up CPU time.
    for (let i = 0; i < 9999999; i++) {
      let dummyValue = Math.random() * Math.random();
    }
  }
  if (!isCloseEnough(window.pageYOffset, currentScroll)) { // does it still match?
    document.querySelector(".overlay").innerHTML += "ERROR! " + window.pageYOffset + " !== " + currentScroll + "<br>";
  }
}

changeScroll();
              
            
!
999px

Console