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

              
                <h1>Folding tutorial concept</h1>
<button id="toggle" class="fa-eye-slash"></button>

<div class="instructions">
  <h2>Self-invoking anonymous functions</h2>
  <p>Since we don't want to pollute the global namespace, we're going to encapsulate our demo within a self-invoking anonymous function. It starts like this:</p>
</div>
<div class="code">
  <pre><code class="language-javascript">;(function () {</code></pre>
</div>
<div class="instructions">
  <p>Note that we've added a <code class="language-javascript">;</code> at the beginning of the line. This is in case our file gets concatinated with something that didn't end with a semicolon.</p>
  <p>From here, we can include our function body. Let's write fizzbuzz.</p>
</div>
<div class="code">
  <pre><code class="language-javascript">    //fizzbuzz
    for (var i = 1; i <= 100; i++) {
        if (i % 15 === 0) {
            console.log('FizzBuzz');
        } else if (i % 3 === 0) {
            console.log('Fizz');
        } else if (i % 5 === 0) {
            console.log('Buzz');
        } else {
            console.log(i);
        }
    }</code></pre>
</div>
<div class="instructions">
  <p>This function prints 1 to 100 with "fizz" taking the place of any multiple of 3, "buzz" taking the place of any multiple of 5, and "fizzbuzz" taking the place of any multiple of both 3 and 5.</p>
  <p>Now that our function is defined, all we need to do is call it.</p>
</div>
<div class="code">
  <pre><code class="language-javascript">})();</code></pre>
</div>
<footer>
  <p>Demo brought to you by <a href="http://rileyjshaw.com" target="_blank">rileyjshaw</a>.</p>
</footer>
<script src=//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js></script>

              
            
!

CSS

              
                body
  overflow-y: scroll
  margin: 1.5em auto 0
  font: 27px 'Slabo 27px', serif
  color: #333
  
h1, .instructions, pre, footer
  width: 600px
  margin: auto

h1
  margin-bottom: .5em
    
h2
  margin-top: 0
  
h1, .instructions, footer
  max-width: 94%
    
.instructions
  overflow: hidden
  max-height: 400px
  transition: max-height 0.9s, opacity 0.3s 0.3s
  
  .instructions-hidden &
    max-height: 0
    opacity: 0
    transition: max-height 0.9s, opacity 0.3s

pre
  font-size: 24px
    
.code
  background: #002b36
  
#toggle
  position: fixed
  right: 12px
  bottom: 12px
  height: 48px
  width: 48px
  border: 0
  outline: 0
  font: 22px Fontawesome
  border-radius: 24px
  cursor: pointer
  color: #fff
  background: #ff6f00
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.3)

              
            
!

JS

              
                function toggleClass (el, className) {
  if (el.classList) {
    el.classList.toggle(className);
  } else {
    var classes = el.className.split(' ');
    var existingIndex = classes.indexOf(className);

    if (existingIndex >= 0)
      classes.splice(existingIndex, 1);
    else
      classes.push(className);

    el.className = classes.join(' ');
  }
}

var body = document.body;
var toggle = document.getElementById('toggle');

hljs.initHighlightingOnLoad();
toggle.addEventListener('click', function () {
  toggleClass(body, 'instructions-hidden');
  toggleClass(toggle, 'fa-eye');
  toggleClass(toggle, 'fa-eye-slash');
}, false);

              
            
!
999px

Console