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" />
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;0,700;0,900;1,100;1,300;1,400;1,700;1,900&display=swap"
      rel="stylesheet"
    />
  </head>
  <body>
    <div>
      <div id="resizable" class="resizable">
        <div class="example">
          <p class="text text--2xs">My container is less than 101px wide</p>
          <p class="text text--xs">My container is betwween 101px and 360px</p>
          <p class="text text--sm">My container is between 361px and 499px</p>
          <p class="text text--md">My container is between 500px and 699px</p>
          <p class="text text--lg">My container is between 700px and 899px</p>
          <p class="text text--xl">My container is between 900px and 1099px</p>
          <p class="text text--2xl">
            My container is wider than 1099px
          </p>
        </div>
      </div>
      <p>
        Current width:
        <span id="current_width"></span>
      </p>
    </div>
  </body>
</html>

              
            
!

CSS

              
                p {
  font-famile: Lato;
}

.resizable {
  resize: horizontal;
  overflow: scroll;
  width: 350px;
  height: 100px;
  font-family: Lato;
  container: pagination / inline-size;
  --button-width: 36px;
}

/** Base style */
.resizable {
  resize: horizontal;
  overflow: scroll;
  width: 350px;
  font-family: Lato;
  container: example / inline-size;
  --button-width: 36px;
}

/** Base style */
 .text {
    width: 100%;
    height: 100%;
    color: black;
    display: none;
     &--2xs {
       color: #39FEA3;
     }
    &--xs {
      color: #f0f;
    }
    &--sm {
      color: #009018;
    }
    &--md {
      color: #f00;
    }
    &--lg {
      color: #00f;
    }
    &--xl {
      color: #ffc800;
    }
    &--2xl {
      color: #00ffbb;
    }
 }

/* Container queries */
@container example (max-width: 100px) {
  .text {
    display: none;
    &--2xs {
      display: inline;
    }
  }
}

@container example (min-width: 101px) {
  .text {
    display: none;
    &--xs {
      display: inline;
    }
  }
}

@container example (min-width: 361px) and (max-width: 499px) {
  .text {
    display: none;
    &--sm {
      display: inline;
    }
  }
}

@container example (min-width: 500px) and (max-width: 699px) {
  .text {
    display: none;
    &--md {
      display: inline;
    }
  }
}

@container example (min-width: 700px) and (max-width: 899px) {
  .text {
    display: none;
    &--lg {
      display: inline;
    }
  }
}

@container example (min-width: 900px) and (max-width: 1099px) {
  .text {
    display: none;
    &--xl {
      display: inline;
    }
  }
}

@container example (min-width: 1100px) {
  .text {
    display: none;
    &--2xl {
      display: inline;
    }
  }
}

              
            
!

JS

              
                const $target = document.querySelector('#resizable');
const $currentWidth = document.querySelector('#current_width');

window.addEventListener('mousemove', (e) => { 
  const width = $target.getBoundingClientRect().width;
  $currentWidth.innerHTML = `${width}px`;
});
              
            
!
999px

Console