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

              
                <link href='https://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css'>

  
<div class="wrapper">
  <h1>Show Html demos with data uri</h1>
  <textarea id="tx" class="pre">
    <!-- demo -->
   <div id="typeWriter"></div>
    <script type="text/javascript" rel="javascript">
      /*
      * HTML example
      * <div id="typeWriter"></div>
      + https://codepen.io/gavra/pen/tEpzn
      */
      var typeWriter = (function(){
        'use strict';

        // set up text to print, each item in array is new line
        var aText = new Array(
          "This a sample data of demo,", 
            "The demo include javascript code of <a href='https://codepen.io/gavra'>gavra</a>",
          "I include this in my tag ( i love this )",
            "Thanks for see this demo and sorry for my English."
        ),
            iSpeed = 100, // time delay of print out
            iIndex = 0, // start printing array at this posision
            iArrLength = aText[0].length, // the length of the text array
            iScrollAt = 20, // start scrolling up at this many lines
            iTextPos = 0, // initialise text position
            sContents = '', // initialise contents variable
            iRow; // initialise current row

        return{  
          run: function(){
            sContents =  ' ';
            iRow = Math.max(0, iIndex-iScrollAt);
            var destination = document.getElementById("typeWriter");

            while ( iRow < iIndex ) {
              sContents += aText[iRow++] + '<br />';
            }
            destination.innerHTML = sContents + aText[iIndex].substring(0, iTextPos) + "_";
            if ( iTextPos++ == iArrLength ) {
              iTextPos = 0;
              iIndex++;
              if ( iIndex != aText.length ) {
                iArrLength = aText[iIndex].length;
                setTimeout("typeWriter.run()", 500);
              }
            } else {
              setTimeout("typeWriter.run()", iSpeed);
            }  
          }
        };
      })();
      // run typewriter 
      typeWriter.run();
    </script>
  </textarea>
  <a href="#" id="c" class="btn">Convert</a>
  <pre id="p_uri" class="pre"></pre>
  <span class="preview"></span>
</div>

              
            
!

CSS

              
                
*,
*:after,
*:before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
 
/*  = scroll
----------------------------*/
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar {
  background:#ecf0f1;
}
::-webkit-scrollbar-thumb {
  background: #ddd;
}

/*  = body
----------------------------*/
html,body{
  position:relative;
  height:100%;
}
body{
  background:#fff; 
  background-size:cover;
  color:#777;
  overflow:auto;
  font-family: 'Oswald', 'sans-serif';
  font-weight: 400;
}
.wrapper{
  display: block;
  margin: 5px auto;
  width: 90%;
}
.btn{
  margin:5px;
  color: #FFF;
  display: inline-block;
  background:#3498db;
  border: 1px solid #2980b9;
  padding:0.5em 1em;
  text-align: center;
  text-decoration:none;
  outline: none;
  white-space: nowrap;
  cursor: pointer;
  font-family: 'sans-serif';
  font-weight: 300;
  font-size: 18px;
  border-radius: 2px;
  transition:all 0.2s ease;
}
.btn:hover{
  border-color: #eee;
  background: #C0392B;
  color: #eee;
  transition:all 0.2s ease;
}

.pre {
  overflow: auto;
  width:100%;
  height:100px;
  margin: auto;
  margin-bottom:16px;
  display: block;
  border: 5px solid #eee;
  background:#fdfdfd;
  color:#2980b9;
  font-size:13px;
  font-family: cursive;
  font-weight: 300;
  word-break: break-all; 
  word-wrap: break-word;
  white-space: pre;
  white-space: -moz-pre-wrap;
  white-space: pre-wrap;
  white-space: pre\9; 
}

#tx{
  height: 200px;
}

              
            
!

JS

              
                var showDemos = (function(){
  'use strict';
  return {
    run: function(){
      this.events();
    },
    _qS: function(el){
      return document.querySelector(el);
    },
    enc: function(el){
      return 'data:text/html;charset=utf-8,<body>' + encodeURIComponent(el.value);
    },
    dec: function(el){    
      return decodeURIComponent(
        el.value.replace('data:text/html;charset=utf-8,',''));
    },
    events: function(){
      
      var self = this,
          tx = this._qS('#tx'),
          p_uri = this._qS('#p_uri'),
          convert = this._qS('#c'),
          preview = this._qS('.preview') ;

      convert.addEventListener('click',function(){
        p_uri.innerHTML = self.enc(tx);
        preview.innerHTML = '<a href="'+self.enc(tx)+'" class="btn" target="blank">Preview</a>'+
        '- Or -'+'<a href="'+self.enc(tx)+'" class="btn" download>Download</a>';
      },false);

      tx.addEventListener('keydown',function(){
        p_uri.innerHTML = '';
      },false);
    }
  };
})();
showDemos.run();


              
            
!
999px

Console