Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <div class="item item-1">I am an item.</div>
<div class="item item-2">I am an item.</div>
<div class="item item-3">I am an item.</div>
<div class="item item-4">I am an item.</div>
<div class="item item-5">I am an item.</div>
              
            
!

CSS

              
                body {
  display: flex;
}

.item {
  padding: 1rem;
  margin: 1rem 0 1rem 1rem;
  border: 1px solid #ccc;
  max-width: 10rem;
  box-shadow: 2px 5px 20px rgba(black, 0.07);
  border-radius: 0.2rem;
}
              
            
!

JS

              
                /*
METHOD ONE
*/

// first select all of the items..
const items = document.getElementsByClassName('item');
// At this point, items = a HTMLCollection with 5 items
// HTMLCollection(5) [div.item,div.item,div.item,div.item,div.item ]

// Using the new spread operator, we can transform this HTMLCollection
// into an array, which gives us access to a bunch of useful methods
const itemsArray = [...items];
// itemsArray now = a array(5) [div.item, div.item, div.item, div.item, div.item]

// now we have an array we can easily use over them using forEach
itemsArray.forEach((item, index) => {
  console.log(
    // each of items is an 'Element', which gives you access to a bunch
    // of object methods https://developer.mozilla.org/en-US/docs/Web/API/Element
    item,
    // also, you can access the index of the loop
    index
  );
});

/*
METHOD TWO
but we can make this one step shorter!
Also if you don't need the index, feel free to omit it
note we already defined const items above
*/
[...items].forEach(item => console.log(item));

/*
METHOD THREE
or if you were feeling really wild...
this is potentially less performant, if there's any chance
you'll be running this loop more than once, you'll definately
want to store the HTMLCollection in memory first, but that's up to you
*/
[...document.getElementsByClassName('item')].forEach(item => console.log(item));

/*
BONUS ROUND
*/
Array.from(items).forEach(item => console.log(item));
              
            
!
999px

Console