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

              
                <section>
  <h3>This grid uses <code>order: 1</code> to attempt to move the third item to the start...</h3>
  <p>But it didn't work! Because all the other items implicitly have a higher order.</p>
<div id="grid-order-0" class="grid">  
   <div class="item">
     <h4>1</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>
   <div class="item">                    
     <h4>2</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>
   <div class="item">                    
     <h4>3</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>                                
  <div class="item">                    
       <h4>4</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>
   <div class="item">                    
     <h4>5</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>                                
</div>
</section>
<section>
  <h3>This grid successfully uses <code>order: 1</code> to move the third item to the start.</h3>
  <p> All other items are explicitly given a lower order by using <code>order: 2</code>to allow this.</p>
<div id="grid-order-1" class="grid">  
   <div class="item">
     <h4>1</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>
   <div class="item">                    
     <h4>2</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>
  <div class="item">
    <h4>3</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>                                
  <div class="item">                    
       <h4>4</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>
   <div class="item">                    
     <h4>5</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>                                
</div>
</section>
<section>
  <h3>This grid uses <code>order: -1</code> on it's third element</h3>
 <p> giving it a higher order than the implicit order of the other elements. </p>
  
<div id="grid-order-2" class="grid">  
   <div class="item">
     <h4>1</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>
   <div class="item">                    
     <h4>2</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>
   <div class="item">                    
     <h4>3</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>                                
  <div class="item">                    
       <h4>4</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>
   <div class="item">                    
     <h4>5</h4>
     <div class="kitten-container">
       <img class="kitten" alt="Kitten">
     </div>
   </div>                                
</div>
</section>
              
            
!

CSS

              
                .grid {
    display: grid;
    grid-gap: 20px;  
    grid-template-columns: repeat(3, 1fr);
}

.grid .item {
  background-color: gainsboro;
  border: 2px solid grey;
  border-radius: 3px;  
  padding: 16px;
}

#grid-order-0 .item:nth-child(3) {
  order: 1;
}

#grid-order-1 .item {
  order: 2;
}

#grid-order-1 .item:nth-child(3) {
  order: 1;
}

#grid-order-2 .item:nth-child(3) {
  order: -1;
}

.kitten-container {
  display: flex;      
  justify-content: center;
}

.grid .item:nth-child(odd) {
    background-color: lavender;
    border: 2px solid grey;
}

section {
  margin-top: 3em;
}
              
            
!

JS

              
                 class PlaceKittenUrl {
   constructor() {
     this.height = 100
     this.width = 100
     this.image = Math.floor(Math.random() * 16)
   }        

   height(newHeight) {
     this.height = newHeight
     return this
   }

   width(newWidth) {
     this.width = newWidth
     return this
   }

   url() {
     return  `https://placekitten.com/${this.width}/${this.height}?image=${this.image}`
   }
 }

const section1Kittens = document.getElementsByClassName("kitten")
for(const kitten of section1Kittens) {
  kitten.src = new PlaceKittenUrl().url()       
}
              
            
!
999px

Console