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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <section class="article-info"></section>
<div class="article-body">
<h1 id="title">Title</h1>
<h1 id="second-title">Second Titles</h1>
<h3>Sub Sub</h3>
<h1>Third Title</h1>
<h2>The sub</h2>
              .toc ul {
  list-style: none;

.toc li {
              var $headers = $('.article-body h1');

if ($headers.length > 1) {
  var $toc = $('<div class="toc">');
  var $firstUl = $('<ul>');
  var $currentUl = $firstUl;
  var previous_level = 1;


  // start with first H1

function insertHeading(heading) {
  var $heading = $(heading);
  // what level heading are we on?
  var current_level = headingLevel(heading);

  // if it's an H1, add it to the original list
  if (current_level === 1) {
    newLi($heading, $firstUl);
    $currentUl = $firstUl;

  // if it's the same as the one before it, add it to the current list
  else if (current_level === previous_level) {
    newLi($heading, $currentUl);

  // if it's one level higher than the one before it... time to make a new nested list
  else if (current_level > previous_level) {
    newLi($heading, $currentUl);

  previous_level = current_level;

  var $nextHeading = $heading.nextAll("h1, h2, h3, h4, h5, h6").first()[0];
  if ($nextHeading) insertHeading($nextHeading);

function nestUl() {
  var $newUl = $('<ul>');
  $currentUl = $newUl;

function headingLevel(heading) {
  switch (heading.nodeName) {
    case 'H1':
      return 1;
    case 'H2':
      return 2;
    case 'H3':
      return 3;
    case 'H4':
      return 4;
    case 'H5':
      return 1;
    case 'H6':
      return 6;
      return 0;

function newLi(heading, $list) {
  var $heading = $(heading);
  var $wrapper = $('<li></li>');
  var $link = $('<a>').prop('href', '#' + $heading.prop('id'));
  $link.html('<span class="index"></span> ' + $heading.text());


  var place_in_parent = $list.children('li').length;

  if ($list.parent()[0].nodeName === 'DIV') {
  } else {
    $link.find('.index').text($wrapper.parent().prev('li').find('.index').text() + '.' + place_in_parent)
  $heading.text($link.find('.index').text() + ' ' + $heading.text())
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.