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 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.


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.


                <div id="root">
  <div id="target"></div>

<div id="output">intersectionRatio: <pre></pre></div>

<div id="buttons">
  <button id="center">center</button>
  <button id="left">left</button>
  <button id="top">top</button>
  <button id="corner">corner</button>
  <button id="large">large</button>


                html {
  box-sizing: border-box;
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
*, *:before, *:after {
  box-sizing: inherit;
body {
  background-color: #1d1e22;
  margin: 0;
  padding: 0;

#root {
  align-items: center;
  background-color: #FFF;
  border: 3px solid rebeccapurple;
  display: flex;
  height: 400px;
  justify-content: center;
  margin: 20px auto;
  overflow: visible;
  position: relative;
  width: 400px;

#target {
  background-color: rebeccapurple;
  background-image: radial-gradient(ellipse at center, #ffffff 0%,#ffffff 14%,#663399 15%,#663399 34%,#ffffff 35%,#ffffff 50%,#663399 51%,#663399 99%);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 300px 300px;
  height: 300px;
  pointer-events: none;
  transition: 0.5s;
  width: 300px;
#target.left {
  opacity: 0.5;
  transform: translate3d(-200px, 0, 0);
} {
  opacity: 0.5;
  transform: translate3d(0, -200px, 0);
#target.corner {
  opacity: 0.5;
  transform: translate3d(200px, -200px, 0);
#target.large {
  height: 500px;
  opacity: 0.5;

#output {
  color: #FFF;
  margin: 20px auto;
  width: 400px;
#output pre {
  display: inline;
  font-size: 16px;
  padding: 0 10px;

#buttons {
  display: flex;
  justify-content: space-around;
  margin: 20px auto;
  position: relative;
  width: 400px;
  z-index: 2;
#buttons button {
  background-color: #FFF;
  border: 3px solid rebeccapurple;
  color: rebeccapurple;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  padding: 0.5rem 1rem;
  transition: 0.25s 0.25s;


                const root = document.querySelector('#root');
const target = document.querySelector('#target');
const output = document.querySelector('#output pre');
const io_options = {
  root: root,
  rootMargin: '0px',
  threshold: [...Array(100).keys()].map(x => x / 100)
let io_observer;

function io_callback (entries) {
  output.innerText = entries[0].intersectionRatio;

function clickHandler (e) {

document.querySelectorAll('#buttons button').forEach(function (btn) {
  btn.addEventListener('click', clickHandler);

io_observer = new IntersectionObserver(io_callback, io_options);