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

              
                <div class="container">
  <div class="column">
    <h2>CSS Version</h2>
    <button id="populateCss">Populate 1000 CSS Items</button>
    <div id="cssContainer"></div>
  </div>
  <div class="column">
    <h2>JavaScript Version</h2>
    <button id="populateJs">Populate 1000 JS Items</button>
    <div id="jsContainer"></div>
  </div>
</div>
              
            
!

CSS

              
                .container {
  display: flex;
  justify-content: space-between;
  padding: 20px;
}
.column {
  width: 48%;
}
.item {
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid #ddd;
}
button {
  margin-bottom: 20px;
  cursor: pointer;
}

/* Styles for CSS version */
.css-accordion {
  border: 1px solid #ccc;
  margin-bottom: 5px;
}
.css-accordion .content {
  display: none;
}
.css-accordion input[type="checkbox"] {
  display: none;
}
.css-accordion input[type="checkbox"]:checked + label + .content {
  display: block;
}
.css-accordion label {
  cursor: pointer;
  display: block;
  padding: 15px;
  font-weight: bold;
  background-color: #f1f1f1;
}
.css-accordion label:hover {
  background-color: #e0e0e0;
}

/* Animation for CSS version */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.css-accordion input[type="checkbox"]:checked + label + .content {
  animation: fadeIn 0.5s ease-in-out;
}

/* Styles for JavaScript version */
.js-accordion {
  border: 1px solid #ccc;
  margin-bottom: 5px;
}

.header {
  padding: 15px;
  background-color: #f1f1f1;
  cursor: pointer;
  font-weight: bold;
}

.content {
  display: none;
  padding: 15px;
  background-color: #fff;
}

              
            
!

JS

              
                // Function to generate random text
function generateRandomText(length) {
  const chars =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  let result = "";
  for (let i = 0; i < length; i++) {
    result += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  return result;
}

// CSS Version
document.getElementById("populateCss").addEventListener("click", () => {
  const container = document.getElementById("cssContainer");
  container.innerHTML = ""; // Clear existing content
  performance.mark("cssStart");
  for (let i = 0; i < 1000; i++) {
    const accordionHtml = `                
                      <div class="css-accordion">
                        <input type="checkbox" id="css-acc-${i}">
                        <label for="css-acc-${i}">Item ${i + 1}</label>
                        <div class="content">
                            <p>${generateRandomText(20)}</p>
                        </div>
                    </div>
                `;
    container.innerHTML += accordionHtml;
  }
  performance.mark("cssEnd");
  performance.measure("cssPopulation", "cssStart", "cssEnd");
  console.log(
    "CSS Population Time:",
    performance.getEntriesByName("cssPopulation")[0].duration
  );
});

// JavaScript Version
document.getElementById("populateJs").addEventListener("click", () => {
  const container = document.getElementById("jsContainer");
  container.innerHTML = ""; // Clear existing content
  performance.mark("jsStart");
  for (let i = 0; i < 1000; i++) {
    const accordionHtml = `
                    <div class="js-accordion">
                        <div class="header">Item ${i + 1}</div>
                        <div class="content" style="display: none;">
                            <p>${generateRandomText(20)}</p>
                        </div>
                    </div>
                `;
    container.innerHTML += accordionHtml;
  }
  // Add event listeners to all accordions
  document.querySelectorAll(".js-accordion .header").forEach((header) => {
    header.addEventListener("click", () => {
      const content = header.nextElementSibling;
      content.style.display =
        content.style.display === "none" ? "block" : "none";
    });
  });
  performance.mark("jsEnd");
  performance.measure("jsPopulation", "jsStart", "jsEnd");
  console.log(
    "JS Population Time:",
    performance.getEntriesByName("jsPopulation")[0].duration
  );
});

              
            
!
999px

Console