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 Key Generator
label Length
input[id='input' type='number' value='4' max='197']
button[id='button'] Generate a key!
              
            
!

CSS

              
                @import compass

$fg: #6CD5FA
$bg: #59AFD5

html
  padding-bottom: 2em
  text-align: center
  font-family: sans-serif
  color: $fg
  background: $bg
    
h1
  padding: .4em
  font-weight: bold
  font-size: 60px
    
label
  font-size: 24px
  
button, input
  border: 0
  outline: 0
    
input
  display: block
  height: 60px
  width: 120px
  margin: .5em auto
  padding-left: .44em
  font-size: 36px
  text-align: center
  color: $bg
  background: $fg
  
  &::placeholder
    color: $bg
  
button
  margin: .5em
  padding: .25em .5em
  font-weight: bold
  font-size: 36px
  color: $bg
  background: $fg
  cursor: pointer
  
p
  font-family: monospace
      
              
            
!

JS

              
                var input = document.getElementById('input');
var button = document.getElementById('button');

input.addEventListener('input', function() {
  this.value = Math.min(Math.max(this.value, 1), 197);
});

button.addEventListener('click', function() {
  var length = input.value || 4;
  var p = document.createElement('p');
  p.textContent = generateSessionId(length);
  document.body.appendChild(p);
});

var generateSessionId = (function() {
    var memo = {};

    // returns a series of chars, length len
    var charSeries = function(len, char) {
        for (var series = ''; series.length < len;)
            series += char;
        return series;
    }

    return function(len) {
        var floor, ratio, memoVal = memo[len];
        if (memoVal) {
            floor = memoVal.floor;
            ratio = memoVal.ratio;
        } else {
            // '10..0' in base 36
            floor = parseInt(1 + charSeries(len, '0'), 36);
            // '1z..z' in base 36 / floor gives 1.x, -1 = x
            ratio = parseInt(1 + charSeries(len, 'z'), 36) / floor - 1;
            // memoize it for next time
            memo[len] = {
                floor: floor,
                ratio: ratio
            };
        }
        return (
            // 1 * floor = '00..0', (1 + ratio) * floor = 'zz..z'
            Math.floor((1 + Math.random() * ratio) * floor)
            // 36 parses it to use 0-9 and a-z
            .toString(36)
            // kick the leading '1' off the string
            .substring(1)
        );
    }
})();
              
            
!
999px

Console