cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="cm-wrapper">
  <div class="cm-code-wrapper">

    <textarea class="CodeMirror code-html" name="code">HTML</textarea>
    <textarea class="CodeMirror code-css" name="code">Css</textarea>
    <textarea class="CodeMirror code-js" name="code">Javascript</textarea>
    <iframe class="result"></iframe>
    
  </div>
</div>



<div class="cm-wrapper">
  <div class="cm-code-wrapper">

    <textarea class="CodeMirror code-html" name="code">HTML</textarea>
    <textarea class="CodeMirror code-css" name="code">Css</textarea>
    <textarea class="CodeMirror code-js" name="code">Javascript</textarea>
    <iframe class="CodeMirror result"></iframe>
    
  </div>
</div>
            
          
!
            
              .cm-wrapper {
  width: 600px;
  margin-bottom: 40px;
}
.cm-code-wrapper {
  position: relative;
  height: 400px;
}
.cm-btn {
  display: inline-block;
  width: 100px;
  background: #ccc;
  color: #fff;
  text-align: center;
  padding: 10px 0;
}
.CodeMirror,
.result{
  position: relative;
  width: 100%;
  height: inherit;
}
.CodeMirror:first-child {
  background: red;
}
.CodeMirror:nth-child(2) {
  display: none;
  background: yellow;
}
.CodeMirror:nth-child(3) {
  display: none;
  background: green;
}
.resource {
  background: pink;
}
.result {
  display: none;
  background: blue;
}
.fullscreen {
  position: fixed;
  top:  0;
  left: 0;
  z-index: 999;
  margin: 0;
}
            
          
!
            
              
// Create button
function createButton(a, b, c){
  var cc = document.getElementsByClassName("cm-code-wrapper"), wrp, btn, tx;
  for (var i=0; i<cc.length; i++){
    if (c){
      
      if (cc[i].parentNode.getElementsByClassName("cm-btn-wrapper").length === 0){
        wrp = document.createElement("div");
        wrp.className = "cm-btn-wrapper";
        cc[i].parentNode.insertBefore(wrp, cc[i]);
      }
      
      if(cc[i].parentNode.getElementsByClassName(a).length === 0 && cc[i].getElementsByClassName(c).length !== 0){
        btn = document.createElement("div");
        tx = document.createTextNode(b);
        btn.className = a;
        btn.appendChild(tx);
        cc[i].parentNode.children[0].appendChild(btn);
      }
    }
    else {
      btn = document.createElement("div");
      tx = document.createTextNode(b);
      btn.className = a;
      btn.appendChild(tx);
      cc[i].parentNode.children[0].appendChild(btn);
    }
  }
}

createButton("cm-btn cm-btn-html", "HTML", "code-html");
createButton("cm-btn cm-btn-css", "CSS", "code-css");
createButton("cm-btn cm-btn-js", "JS", "code-js");
createButton("cm-btn cm-btn-result", "RESULT", "result");
createButton("cm-btn cm-btn-fullscreen", "FULLSCREEN");

// Toogle

function toggle(a, b){
  var g = document.getElementsByClassName(a);
  function tgl(){
    var h = this.parentNode.parentNode.children[1].children;
    for (var i=0; i<h.length; i++){
      h[i].style.display = "none";
    }
    if (b === "result"){
      this.parentNode.parentNode.getElementsByClassName(b)[0].style.display = "block";
    } else {
      this.parentNode.parentNode.getElementsByClassName(b)[0].style.display = "block";
    }
    if (!(this.className.match("btn-active"))){
      for (var j=0; j<this.parentNode.children.length; j++){
        this.parentNode.children[j].className = this.className.replace(" btn-active", "");
      }
      this.className += " btn-active";
    }
  }
  for (var i=0; i<g.length; i++){
    g[i].onmousedown = tgl;
  }
}

toggle("cm-btn-html", "code-html");
toggle("cm-btn-css","code-css");
toggle("cm-btn-js","code-js");
toggle("cm-btn-result","result");

// Fullscreen

var cmBtnFullScreen = document.getElementsByClassName("cm-btn-fullscreen"),
    windowWidth, windowHeight;
function fullScreen(){
  var parent = this.parentNode.parentNode,
      code = parent.getElementsByClassName("cm-code-wrapper");
  if (parent.clientWidth === window.innerWidth){
    parent.style.width = windowWidth + "px";
    parent.style.height = windowHeight + "px";
    this.className = this.className.replace(" cmm", "");
    parent.className = parent.className.replace(" fullscreen", "");
    document.getElementsByTagName("body")[0].style.overflow = "scroll";
  } else {
    windowWidth = parent.clientWidth;
    windowHeight = parent.clientHeight;
    this.className += " cmm";
    parent.className += " fullscreen";
    parent.style.width = window.innerWidth + "px";
    parent.style.height = window.innerHeight + "px";
    document.getElementsByTagName("body")[0].style.overflow = "hidden";
  }
  
  for (var j=0; j<code.length; j++){
    code[j].style.height = (parent.clientHeight - this.parentNode.clientHeight) + "px";
  }
}

for (var i=0; i<cmBtnFullScreen.length; i++){
  cmBtnFullScreen[i].onclick = fullScreen;
}

// Iframe stuff

var btnResult = document.getElementsByClassName("cm-btn-result");

function hack(){
  var styleElmn = document.createElement("style"),
      scriptElmn = document.createElement("script"),
      a = this.parentNode.parentNode,
      b = a.getElementsByClassName("result")[0].contentWindow.document.body;

  a.getElementsByClassName("result")[0].contentWindow.document.head.appendChild(styleElmn);
  styleElmn.innerHTML = a.getElementsByClassName("code-css")[0].value;
  b.innerHTML = a.getElementsByClassName("code-html")[0].value;
  b.appendChild(scriptElmn);
  scriptElmn.innerHTML = a.getElementsByClassName("code-js")[0].value;
}

for (var i=0; i<btnResult.length; i++){
  btnResult[i].onclick = hack;
}
            
          
!
999px
Loading ..................

Console