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

              
                <button id="show_all" onclick="show_all()">all</button>
<button id="show_red" onclick="show_red()">red</button>
<button id="show_blue" onclick="show_blue()">blue</button>

<div class="item_wrapper">
<div class="item red" ></div>
<div class="item blue" ></div>
<div class="item red blue"></div>
</div>
              
            
!

CSS

              
                .item{
  width:100px;
  height:100px;
  margin-right:10px;
  margin-bottom:10px;
  display:inline-block;
}
.item.red{
  background:red;
}
.item.blue{
  background:blue;
}
.item.blue.red{
  background:purple;
}
              
            
!

JS

              
                //find all elements tagged "red"
var reds = document.querySelectorAll('.red');

//find all elements tagged "blue"
var blues = document.querySelectorAll('.blue');

//find all elements with "item" class
var alls = document.querySelectorAll('.item');

//function to initially loop through all items and hide them
function hide_init(){
   for (var i = 0; i < alls.length; ++i) { 
 alls[i].style.display = 'none'; 
}
}

function show_red(){  
//call the inital hide function
hide_init();
//loop through red-tagged items and show them  
   for (var i = 0; i < reds.length; ++i) { 
 reds[i].style.display = 'inline-block'; 
} 
}

function show_blue(){  
//call the inital hide function
hide_init();
//loop through blue-tagged items and show them  
   for (var i = 0; i < blues.length; ++i) { 
 blues[i].style.display = 'inline-block'; 
} 
}

function show_all(){  
  //loop through all items and show them
   for (var i = 0; i < alls.length; ++i) { 
 alls[i].style.display = 'inline-block'; 
} 
}
              
            
!
999px

Console