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

              
                <pre class="code__block">
  <code class="language-java">
  // TODO keywords like this and "strings" 
  // should not be higlighted in comments
  public class Highlighter implements Nothing
  {
    private static final Highlighter INSTANCE = new Highlighter();
    private static final char IDENTIFIER = 'h';

    public static Highlighter getInstance ()
    {
      return INSTANCE;
    }
    
    public boolean isHighlighted ( Element el )
    {
      return el.hasClass( "highlighted" );
    }
    
    public void highlight ( Element el )
    {
      el.addClass( "highlighted" );
    }
  }
  </code>
</pre>
<pre class="code__block">
  <code class="language-css">
  .language__css--selector-id {
    color: dodgerblue;
  }

  .language__css--selector-class {
    color: orchid;
  }

  .language__css--selector-attr {
    color: mediumseagreen;
  }

  .language__css--selector-pseudo {
    color: steelblue;
  }

  .language__css--selector-colon {
    color: olive;
  }

  .language__css--keyword {
    color: darkorange;
  }
  </code>
</pre>
<pre class="code__block">
  <code class="language-xml">
  <syntaxhl>
    <languages>
      <language id="1">
        <name>CSS</name>
      </language>
      <language id="2">
        <name>HTML/XML</name>
      </language>
    </languages>
  </syntaxhl>
  </code>
</pre>
<pre class="code__block">
  <code class="language-lorem">
   Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore
   et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
   Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
   amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
   aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
   gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  </code>
</pre>



              
            
!

CSS

              
                .code__block {
  background-color: #F2F2F2;
  padding: 10px;
  border-left: 5px rgb(190,13,13) solid;
  box-shadow:
      0px 2px 4px 0 white inset,
      0px -2px 4px 0 white inset;
  overflow-x: auto;
  overflow-y: hidden;
  color: black;
}

.code__block code {
  font-family: monospace;
}

.code__block code:hover {
  cursor: text;
}

.code__line {
}

.code__line--number {
  color: gray;
}

/* CSS */
.language__css--selector-id {
  color: dodgerblue;
}

.language__css--selector-class {
  color: orchid;
}

.language__css--selector-attr {
  color: mediumseagreen;
}

.language__css--selector-pseudo {
  color: steelblue;
}

.language__css--selector-colon {
  color: olive;
}

.language__css--keyword {
  color: darkorange;
}

/* XML */
.language__xml--tag {
  color: red;
}

.language__xml--tag-inner {
  color: black;
}

.language__xml--tag-sign {
  color: darkred;
}

.language__xml--tag-attr {
  color: blue;
}

.language__xml--tag-value {
  color: green;
}

/* JAVA */
.language__java--comment {
  color: saddlebrown;
}

.language__java--keyword {
  color: purple;
  font-weight: bold;
}

.language__java--quoted {
  color: blue;
}

.language__java--constant {
  font-weight: bold;
  font-style: italic;
  color: green;
}

.test {
  color: yellow;
}

.language__lorem--keyword {
  color: green
    ;
}

.language__lorem--lorem {
  color: orange;
}
              
            
!

JS

              
                const count = (str, regx) => {
  return ((str || '').match(regx) || []).length
};

var syntaxhl = {
  register: function ( lang ) {
    for ( let el of lang.elements ) {
      var elwe = el.innerHTML.replace( /&/g, "&amp;" ).replace( /</g, "&lt;" ).replace( />/g, "&gt;" ).replace( /"/g, "&quot;" );

      if ( typeof lang.hl !== "undefined" ) {
        lang.hl.nm.forEach( function ( it ) {
          elwe = style( elwe, it.regx, it.cN );
        } );

        if ( typeof lang.hl.kw !== "undefined" ) {
          lang.hl.kw.k.split( /\s+/ ).forEach( function ( kw ) {
            elwe = style( elwe, new RegExp( `(${kw})(?!=|'|-|_)`, "gm" ), lang.hl.kw.cN );
          } );        
        }
      }
      
      elwe = ln( elwe );
      elwe = elwe.replace( /^(.*)$/gm, "<span class=\"code__line\">$&</span>" );
      el.innerHTML = elwe;
    }

    function style ( elwe, regExp, className ) {
      return elwe.replace( regExp, `<span class='${className}'>$&</span>` );
    }

    function ln ( elwe ) {
      var c = count( elwe, /\n/g );
      var i = 0;  
      if ( typeof lang.toggles === "undefined" || lang.toggles.ln === true ) {
        return elwe.replace( /\n/g, function ( $0 ) {
          if ( ++i == c )  return "\n"; 
          if ( i < 10 )  return `\n<span class="code__line--number"> ${i} |&nbsp;</span>`;  
          return `\n<span class="code__line--number">${i} |&nbsp;</span>`;
        } );
      }
      else {
        return elwe.replace( /\n/g, function ( $0 ) {
          if ( ++i == c )  return "\n"; 
          return `\n<span class="code__line--number">&nbsp;&nbsp;</span>`;
        } );
      }
    }
  }
}

var java = {
  elements: document.getElementsByClassName( "language-java" ),
  hl: {
    nm: [
      { cN: "language__java--quoted", regx: /&quot;(.*?)&quot;|'[^']*'/gm },
      { cN: "language__java--constant", regx: /[A-Z]+(?:_[A-Z0-9]+)*(?=\s?=|\s?;)/gm },
      { cN: "language__java--comment", regx: /\/\/\s*.*/gm }
    ],
    kw: {
      cN: "language__java--keyword",
      k: "class false synchronized int abstract float char boolean var " +
      "static null if for true while long strictfp finally import " +
      "native final void enum else break transient catch instanceof byte " +
      "super volatile case assert short package default double public " +
      "try this switch continue throws protected private module requires " +
      "exports do new throw return interface extends implements"
    }
  }	
}

var css = {
  elements: document.getElementsByClassName( "language-css" ),
  hl: {
    nm: [
      { cN: "language__css--selector-id", regx: /#[A-Za-z0-9_-]+/gm },
      { cN: "language__css--selector-class", regx: /\.[A-Za-z0-9_-]+/gm },
      { cN: "language__css--selector-attr", regx: /[a-zA-Z0-9\_\-\+\(\)"'.]+(?=:\s)/gm },
      { cN: "language__css--selector-pseudo", regx: /:(:)?[a-zA-Z0-9\_\-\+\(\)"'.]+/gm }
    ],
    kw: {
      cN: "language__css--keyword",
      k: "inherit inital unset"
    }
  }
}

var xml = {
  elements: document.getElementsByClassName( "language-xml" ),
  hl: {
    nm: [
      { cN: "language__xml--tag-attr", regx: /[a-zA-Z0-9\_\-\+\(\)"'.]+(=.*)&gt;/gm },
      { cN: "language__xml--tag-inner", regx: /(?<=&gt;)(.*?)(?=&lt;)/gm },
      { cN: "language__xml--tag", regx: /&lt;(.*?)&gt;/gm },
      { cN: "language__xml--tag-sign", regx: /&lt;\/?|&gt;/gm },
      { cN: "language__xml--tag-value", regx: /&quot;(.*?)&quot;/gm }
    ]
  }
}

var undef = {
  elements: document.getElementsByClassName( "language-undefined" )
}

var noline = {
  elements: document.getElementsByClassName( "language-noline" ),
  toggles: {
    ln: false
  }
}


var lorem = {
  elements: document.getElementsByClassName( "language-lorem" ),
  hl: {
    nm: [
      { cN: "language__lorem--lorem", regx: /(lorem|elitr|consetetur)/gmi }
    ],
    kw: {
      cN: "language__lorem--keyword",
      k: "ipsum"
    }
  },
  toggles: {
    ln: true
  }
}



syntaxhl.register( undef );
syntaxhl.register( noline );
syntaxhl.register( java );
syntaxhl.register( css );
syntaxhl.register( xml );

              
            
!
999px

Console