123

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.

            
              <div class="container">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sed mauris bibendum, vehicula lacus eget, tempus sem. Morbi pretium metus eu accumsan tempor. Suspendisse potenti. Praesent id elit in magna posuere commodo. Duis id lectus a est sodales hendrerit. Sed auctor vehicula urna sit
    amet semper. Duis congue, enim ut condimentum volutpat, velit ex pulvinar lorem, sed luctus turpis nunc quis eros.</p>

  <button class="toggle-btn">
    <span class="more show">
      Show more info
      <svg width="24" height="24" viewBox="0 0 24 24">
        <path d="M0 7.33l2.829-2.83 9.175 9.339 9.167-9.339 2.829 2.83-11.996 12.17z"/>
      </svg>
    </span>
    <span class="less hide">
      Show less info
      <svg width="24" height="24" viewBox="0 0 24 24">
        <path d="M0 16.67l2.829 2.83 9.175-9.339 9.167 9.339 2.829-2.83-11.996-12.17z"/>
      </svg>
    </span>
  </button>

  <div class="info">
    <p>Mauris convallis, justo eget blandit rutrum, orci tortor vehicula massa, sit amet pulvinar augue urna sit amet velit. Cras tempus odio quis dui sollicitudin efficitur. Aliquam sollicitudin venenatis justo, at sollicitudin dui. Donec diam lorem, suscipit ut lobortis ut, semper aliquam metus. Nam sollicitudin, est id porta lobortis, justo ligula efficitur elit, ut tincidunt lectus nisl sed sapien. Proin ac volutpat lorem. Praesent sodales ultricies velit eget posuere.
      Vestibulum ornare tempor eleifend. Maecenas scelerisque lorem dui, eget commodo sapien lacinia a. Donec lorem erat, sagittis at nisl vel, ultricies tincidunt velit.</p>
  </div>

  <div>Mauris convallis, justo eget blandit rutrum, orci tortor vehicula massa, sit amet pulvinar augue urna sit amet velit. Cras tempus odio quis dui sollicitudin efficitur. Aliquam sollicitudin venenatis justo, at sollicitudin dui. Donec diam lorem, dictum volutpat lorem. Praesent sodales ultricies velit eget posuere.
    Vestibulum ornare tempor eleifend. Maecenas scelerisque lorem dui, eget commodo sapien lacinia a. Donec lorem erat, sagittis at nisl vel, ultricies tincidunt velit.</div>
</div>
            
          
!
            
              * {
  padding: 0;
  margin: 0;
}

button {
  cursor: pointer;
  background: transparent;
  border: none;
  outline: none;
  color: #5a1bbe;
}

button:disabled {
  color: #5a1bbe;
}

svg {
  /*svg images by https://iconmonstr.com*/
  width: 16px;
  height: 16px;
}

.hide {
  display: none;
}

.show {
  display: flex;
}

body {
  font: normal 20px/1.5 Helvetica, sans-serif;
  margin-top: 25px;
  background: #f2f2f2;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 25px;
}

p, 
.toggle-btn {
  margin-bottom: 25px;
}

.toggle-btn {
  display: inline-block;
  font-weight: bold;
}

span {
  display: flex;
  align-items: center;
}

span svg {
  margin-left: 5px;
}

svg path {
  fill: #5a1bbe;
}

.info {
  overflow: hidden;
  transition: height .5s;
}
            
          
!
            
              const toggleBtn = document.querySelector(".toggle-btn");
const info = document.querySelector(".info");
const less = document.querySelector(".less");
const more = document.querySelector(".more");

let infoHeight = info.offsetHeight;
info.style.height = 0;

toggleBtn.addEventListener("click", function() {
  this.disabled = true;

  more.classList.toggle("show");
  more.classList.toggle("hide");
  less.classList.toggle("show");
  less.classList.toggle("hide");

  const infoNewHeight = info.offsetHeight;

  if (infoNewHeight == 0) {
    info.style.height = `${infoHeight}px`;
  } else {
    info.style.height = 0;
  }

  setTimeout(() => {
    this.disabled = false;
  }, 500);
});

window.addEventListener("resize", () => {
  info.style.removeProperty("height");
  infoHeight = info.offsetHeight;

  if(more.classList.contains("hide")) {
    info.style.height = `${infoHeight}px`;
  } else {
    info.style.height = 0;
  }
});
            
          
!
999px
🕑 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.

Console