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

              
                <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>Stagger Spacing</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">
    </head>
    <body>
         <div id="background">
              <!-- the dynamic html would be what is in the span -->
              <!-- user could determine the spacing using the data-spacing attribute -->
               <span id="mainLegals" data-spacing="4">
                   <p>If you don't start, you can't finish</p>
                   <p>If you don't start, you can't finish</p>
                   <p>If you don't start, you can't finish</p>
                   <p>If you don't start, you can't finish</p>
                   <p>If you don't start, you can't finish</p>
                   <p>If you don't start, you can't finish</p>
                   <p>If you don't start, you can't finish</p>
                   
               </span>
         </div>
    </body>
</html>
              
            
!

CSS

              
                body, html {
  margin: 0; padding: 0;
}
p { 
  line-height: 0.1em; 
  font-family: 'arial' 
}
#background {
  position: absolute;
  background-image: url('http://assets.neunie.com/files/tuts/2019/01/30/diagonal.png');
  width: 504px;
  height:380px;
}
              
            
!

JS

              
                function spacingStagger() {
    var mainLegals = document.getElementById("mainLegals");
    var breaks = document.querySelectorAll("#mainLegals p");
    var spacing = mainLegals.dataset.spacing;
    var spaceCounter = parseInt(spacing);

    var spaceWidth = 2; // set the space size to 2px as default
    var baseline = 28; // first line starts from baseline, this could have mad editable from the html too
    var spacer = spaceCounter * spaceWidth;

    if (spacing == 0) {
        console.log("do not stagger the copy");
    } else {

        //if spacing is set to anything other than 0, calculate the values
        for (i = 0; i < breaks.length; i++) {
            breaks[i].style.paddingLeft = baseline + "px";
            baseline = baseline + spacer;
        };
    }
}
//call this function after the page elements have been added
spacingStagger(); 
              
            
!
999px

Console