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="resize">
  <div class="auto-grid" style="
                              --auto-grid-max-columns: 4;
                              --auto-grid-min-size: 18rem;
                              --auto-grid-gap: 1rem;">
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
  </div>
</div>
              
            
!

CSS

              
                /**
 * AUTO-GRID LAYOUT
 *
 * This CSS utility creates a responsive grid layout that automatically adjusts the number of columns
 * based on the available space and specified constraints. It aims to fit as many cells as possible
 * in a single row, while respecting minimum cell width and maximum columns constraints.
 *
 * Customizable Properties:
 * --auto-grid-min-size: Sets the minimum width for each cell in the grid.
 *                       Default is 10rem.
 * --auto-grid-max-columns: Sets the maximum number of columns in the grid.
 *                          Default is 'infinity' (as many as can fit).
 * --auto-grid-gap: Sets the horizontal gap between grid cells. It also sets
 *                  the vertical gap if --auto-grid-gap-vertical is not defined.
 *                  Default is 1rem.
 * --auto-grid-gap-vertical: Specifically sets the vertical gap between rows
 *                           of cells. If not set, it falls back to the value
 *                           of '--auto-grid-gap'.
 *
 * The grid utilizes CSS 'display: grid' with the 'auto-fit' feature and the 'minmax()'
 * function to ensure that cells expand to fill available space while maintaining
 * the set minimum size.
 *
 * Example Usage:
 * <div class="auto-grid" style="--auto-grid-min-size: 10rem; --auto-grid-max-columns: 3; --auto-grid-gap: 0.5rem;">
 *   <!-- grid items here -->
 * </div>
 *
 * The above example will create a grid with a minimum cell width of 10rem, a maximum
 * of 3 columns, and a gap of 0.5rem between both rows and columns.
 */

.auto-grid {
  --max-column-width: 100% / var(--auto-grid-max-columns, infinity) - var(--auto-grid-gap);
  --column-width: max(
    var(--max-column-width),
    min(var(--auto-grid-min-size, 10rem), 100%)
  );

  display: grid;

  grid-template-columns: repeat(auto-fit, minmax(var(--column-width), 1fr));

  /* vertical gap falls back to general gap then falls back to 1rem*/
  gap: var(--auto-grid-gap-vertical, var(--auto-grid-gap, 1rem))
    var(--auto-grid-gap, 1rem);
}

* {
  box-sizing: border-box;
}

body {
  background: #003;
  padding: 2rem;
  color: #fff;
}

.resize {
  padding: 1rem;
  border-radius: 1rem;
  border-end-end-radius: 0;
  border: 1px solid rgb(255 255 255 / 0.8);
  background: rgb(255 255 255 / 0.1);
  resize: horizontal;
  overflow: hidden;
  position: relative;
  max-width: 100%;
  
  &:after {
    content: "Resize me";
    position: absolute;
    inset: auto 0.5rem 0.5rem auto;
    padding: 0.25em 1.25em;
    background: rgb(0 0 50 / 0.8);
    border-radius: calc(1px * infinity);
  }
}

.item {
  height: 10rem;
  background: #f09;
  border: 4px solid white;
  border-radius: 0.5rem;
}
              
            
!

JS

              
                
              
            
!
999px

Console