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

              
                <!-- Intro -->
<div class="intro-box">
  <h2>Random password generator</h2>
</div>

<div class="wrapper">

  <!-- Fields -->
  <div class="fields-box">
    <label for="new-chars">
      <span>Enter posible chars</span>
      <input type="text" id="new-chars">
    </label><label for="new-length">
      <span>Set string length</span>
      <input type="number" id="new-length" min="1">
    </label><label for="new-num">
      <span>Set items number</span>
      <input type="number" id="new-num" min="1">
    </label>
  </div>

  <!-- Table -->
  <div class="table-box">
    <table>
      <!-- Dynamic content! -->
    </table>
  </div>

  <!-- Buttons -->
  <div class="buttons-box">
    <button onclick="download();">Save</button>
    <button onclick="printTable();">Print</button>
  </div>

</div>


<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet">
              
            
!

CSS

              
                /* Global */
* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

html, body {
  min-height: 100%;
}

body {
  background: #80DEEA;
  background: -moz-linear-gradient(-45deg, #80DEEA 0%, #283593 100%);
  background: -webkit-linear-gradient(-45deg, #80DEEA 0%, #283593 100%);
  background: -o-linear-gradient(-45deg, #80DEEA 0%, #283593 100%);
  background: -ms-linear-gradient(-45deg, #80DEEA 0%, #283593 100%);
  background: linear-gradient(135deg, #80DEEA 0%, #283593 100%);
  font-family: 'Open Sans', sans-serif;
  color: #FFFFFF;
}

.wrapper {
  width: 90%;
  max-width: 620px;
  margin: 20px auto;
  border-radius: 3px;
  background: rgba(255,255,255,0.1);
}

/* Intro */
.intro-box {
  width: 80%;
  max-width: 820px;
  margin: 60px auto 40px auto;
}

.intro-box h2 {
  font-size: 2em;
  font-weight: 300;
  text-align: center;
}

/* Fields */
.fields-box {
  padding: 18px 5%;
}

.fields-box label {
  display: inline-block;
  width: 33.33%;
  padding: 6px 12px;
}

.fields-box label span {
  display: block;
  width: 100%;
  margin-bottom: 4px;
  font-size: .8em;
  color: #BBDEFB;
}

.fields-box label input {
  width: 100%;
  padding: 8px;
  color: #29B6F6;
  background: #FFFFFF;
  background: rgba(255,255,255,0.9); 
  border: none;
  outline: none;
  border-radius: 3px;
}

@media only screen and (max-width: 520px){
  .fields-box label {
    width: 100%;
  }
}

/* Table */
.table-box {
  padding: 10px 5%;
  background: rgba(255,255,255,0.1);
}

table, tr, td {
  border: none;
  border-collapse: collapse;
}

.table-box table, 
.table-box table tr {
  width: 100%;
  max-width: 100%;
  padding: 12px;
}

.table-box table tr {
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.table-box table tr:last-child {
  border: none;
}

.table-box table tr td {
  padding: 10px;
  text-align: left;
  outline: none;
}


/* Buttons */
.buttons-box {
  position: fixed;
  width: 54px;
  right: 14px;
  bottom: 18px;
  z-index: 1;
}

.buttons-box button {
  display: inline-block;
  width: 54px;
  height: 54px;
  margin-top: 14px;
  font-size: .8em;
  font-weight: 700;
  color: #2196F3;
  background: #FFFFFF;
  border: none;
  outline: none;
  border-radius: 100%;
  text-align: center;
  box-shadow: 
    0 5px 10px rgba(0,0,0,0.25), 
    0 4px 8px rgba(0,0,0,0.25);
  cursor: pointer;
  transition: ease .2s;
}

.buttons-box button:hover {
  background: #EDE7F6;
  box-shadow: 
    0 10px 20px rgba(0,0,0,0.1), 
    0 8px 16px rgba(0,0,0,0.1);
}

/* Print version */
@media print {
  @page {
    margin: .5cm;
  }

  body {
    border: 6px solid #DDDDDD;
  }

  tr {
    border-bottom: 1px solid #DDDDDD;
  }
  
  .intro-box,
  .fields-box,
  .buttons-box {
    display: none;
  }
}
              
            
!

JS

              
                /*
===============================================================

Hi! Welcome to my little playground!

My name is Tobias Bogliolo. 'Open source' by default and always 'responsive',
I'm a publicist, visual designer and frontend developer based in Barcelona. 

Here you will find some of my personal experiments. Sometimes usefull,
sometimes simply for fun. You are free to use them for whatever you want 
but I would appreciate an attribution from my work. I hope you enjoy it.

===============================================================
*/

//Default values:
var setChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; //Posible chars.
var setLenght = 12; //Output length.
var setNum = 5; //Items length.

//Strings:
var pass = ""; //Password string.
var plainText = ""; //Plain text version.
var textTitle = ""; //Plain text intro.
var fileName = "pass.txt"; //Plain text filename.

//Random password function:
function randString() {
  //Get user values:
  var newChars = $("#new-chars").val();
  var newLenght = $("#new-length").val();
  var newNum = $("#new-num").val();
  //Check valid values:
  if (newChars) {
    setChars = newChars;
  };
  if (newLenght) {
    setLenght = newLenght;
  };
  if (newNum) {
    setNum = newNum;
  };
  //Reset table:
  $("table").empty();
  //Passwords gen:
  for (i=0; i<setNum; i++) {
    //Shuffle chars:
    for(var j = 0; j < setLenght; j++) {
      pass += setChars.charAt(Math.floor(Math.random() * setChars.length));
    };
    //Append items:
    $("table").append("<tr><td>" + parseInt(i+1) + "</td><td>" + pass + "</td><td contenteditable=''>Edit me!</td></tr>");
    //Reset 'pass' string:
    pass = "";
  };
};

//Run password generator:
$(document).ready(function(){
  randString();
});

//Password generator triggers:
$("input").change(function(){
  randString();
});

//Plain text gen:
function toPlain(){
  //Set plain text header:
  textTitle = "\n\n=========================\nRandom password generator\n=========================\n\n"
  //Get raw content:
  tableContent = $("table").html();
  //Remove HTML tags:
  plainText = tableContent.replace(/<tbody>|<\/tbody>|<tr>|<\/td>/g, '').replace(/<\/tr>/g, '\n').replace(/<td>|<td contenteditable="">/g, ' > ');
};

//Download function:
function download() {
  //Get plain text.
  toPlain();
  //Save file:
  var textContent = document.createElement('a');
  textContent.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(textTitle+plainText)); //Set content.
  textContent.setAttribute('download', fileName) //set filename.
  textContent.style.display = 'none'
  document.body.appendChild(textContent)
  textContent.click()
  document.body.removeChild(textContent)
};

//Print function:
function printTable(){
  window.print();
}

//Buttons display:
$(".buttons-box").hide(0);
setTimeout(function(){ 
  $(".buttons-box").fadeIn(300);
}, 5000);

              
            
!
999px

Console