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

              
                <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Critical CSS Demo</title>
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">

    <!-- Critical CSS (inline) -->
  <style>
    body {
      margin: 0;
      font-family: 'Inter', sans-serif;
      background-color: #fff;
      color: #111;
    }

    header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 1.5rem;
      background: #fafafa;
      box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    }

    .logo {
      font-weight: 600;
      font-size: 1.2rem;
    }

    nav a {
      margin-left: 1rem;
      text-decoration: none;
      color: #000;
      font-weight: 500;
    }

    .hero {
      padding: 3rem 1.5rem;
      background-color: #f5f5f5;
      text-align: center;
      border-bottom: 1px solid #ddd;
    }

    .hero h1 {
      font-size: 2.5rem;
      margin-bottom: 1rem;
    }

    .hero button {
      padding: 0.75rem 1.5rem;
      font-size: 1rem;
      border: none;
      background-color: #000;
      color: #fff;
      cursor: pointer;
      border-radius: 4px;
    }
  </style>

</head>
<body>

  <header>
    <div class="logo">MySite</div>
    <nav>
      <a href="#">Home</a>
      <a href="#">Blog</a>
      <a href="#">Contact</a>
    </nav>
  </header>

  <section class="hero">
    <h1>Fast. Clean. Critical CSS.</h1>
    <button id="toggleStyles">Load full styles</button>
  </section>

  <section class="extras" id="extras">
    <div style="padding: 2rem; text-align: center;">
      <p>This content gets prettier once full CSS is loaded.</p>
    </div>
    <div class="product-grid">
      <div class="product"></div>
      <div class="product"></div>
      <div class="product"></div>
      <div class="product"></div>
    </div>
  </section>


</body>
</html>

              
            
!

CSS

              
                    body {
      margin: 0;
      font-family: 'Inter', sans-serif;
      background-color: #fff;
      color: #111;
      transition: all 0.3s ease;
    }

    header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 1.5rem;
      background: #fafafa;
      box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    }

    .logo {
      font-weight: 600;
      font-size: 1.2rem;
    }

    nav a {
      margin-left: 1rem;
      text-decoration: none;
      color: #000;
      font-weight: 500;
    }

    .hero {
      padding: 3rem 1.5rem;
      background-color: #f5f5f5;
      text-align: center;
      border-bottom: 1px solid #ddd;
    }

    .hero h1 {
      font-size: 2.5rem;
      margin-bottom: 1rem;
    }

    .hero button {
      padding: 0.75rem 1.5rem;
      font-size: 1rem;
      border: none;
      background-color: #000;
      color: #fff;
      cursor: pointer;
      border-radius: 4px;
      transition: background 0.2s ease;
    }

    .hero button:hover {
      background-color: #333;
    }

    .extras {
      opacity: 1;
      transform: translateY(0);
      transition: all 0.4s ease;
    }

    .product-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
      gap: 1.5rem;
      padding: 2rem;
      justify-content: center;
      max-width: 880px;       
  margin: 0 auto;
    }

    .product {
      background: none;
      border: 2px dashed #ccc;
      border-radius: 8px;
      padding: 1rem;
      height: 220px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      overflow: hidden;
    }

    .product.loaded {
      background: #fff;
      border: none;
      color: #111;
      font-style: normal;
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }

    .product.loaded img {
      width: 100%;
      border-radius: 6px;
      margin-bottom: 0.5rem;
      filter: blur(10px);
      opacity: 0.5;
      transition: filter 0.8s ease, opacity 0.8s ease;
    }

    .product.loaded img.reveal {
      filter: blur(0);
      opacity: 1;
    }

    .product.loaded h3 {
      margin: 0.5rem 0 0.25rem;
      opacity: 0;
      transform: translateY(10px);
      transition: all 0.4s ease 0.3s;
    }

    .product.loaded h3.reveal,
    .product.loaded p.reveal {
      opacity: 1;
      transform: translateY(0);
    }

    .product.loaded p {
      opacity: 0;
      transform: translateY(10px);
      transition: all 0.4s ease 0.4s;
    }
              
            
!

JS

              
                  const toggleBtn = document.getElementById('toggleStyles');
    let fullStylesLoaded = false;
    let styleLink = null;
    const originalProducts = document.querySelectorAll('.product');

    const images = [237, 238, 239, 240];

    function loadFullStyles() {
      styleLink = document.createElement('link');
      styleLink.rel = 'stylesheet';
      styleLink.href = 'https://unpkg.com/@fontsource/roboto/400.css';
      document.head.appendChild(styleLink);

      originalProducts.forEach((product, index) => {
        setTimeout(() => {
          product.classList.add('loaded');
          product.innerHTML = `
            <img src="https://picsum.photos/id/${images[index]}/200/120" alt="Product image">
            <h3>Product ${index + 1}</h3>
            <p>This is a great product that just got styled.</p>
          `;

          const img = product.querySelector('img');
          const h3 = product.querySelector('h3');
          const p = product.querySelector('p');
          setTimeout(() => {
            img.classList.add('reveal');
            h3.classList.add('reveal');
            p.classList.add('reveal');
          }, 50);

        }, 500 + index * 400);
      });

      toggleBtn.textContent = 'Undo full styles';
      fullStylesLoaded = true;
    }

    function undoFullStyles() {
      if (styleLink) {
        document.head.removeChild(styleLink);
        styleLink = null;
      }

      originalProducts.forEach((product) => {
        product.className = 'product';
        product.innerHTML = '';
      });

      toggleBtn.textContent = 'Load full styles';
      fullStylesLoaded = false;
    }

    toggleBtn.addEventListener('click', () => {
      if (!fullStylesLoaded) {
        loadFullStyles();
      } else {
        undoFullStyles();
      }
    });
              
            
!
999px

Console