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

              
                <section class="grid subgrid-rows">
  <article>
    <h2>This is my main title that might be a bit longer than it should</h2>
    <img src="https://images.unsplash.com/photo-1589225529399-8705282f98e2?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTQyNTE5ODZ8&ixlib=rb-4.0.3&q=85" alt="" />
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras convallis sodales erat vel accumsan. Nam eget massa nec sem vulputate ullamcorper vel quis justo. Duis rhoncus tempor tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras convallis sodales erat vel accumsan.</p>
    <footer>
      <button>Some button</button>
    </footer>
  </article>
  <article>
    <h2>This title is little</h2>
    <img src="https://images.unsplash.com/photo-1484950763426-56b5bf172dbb?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTQyNTE5ODZ8&ixlib=rb-4.0.3&q=85" alt="" />
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras convallis sodales erat vel accumsan. Nam eget massa nec sem vulputate ullamcorper vel quis justo. Duis rhoncus tempor tempus.</p>

    <footer>
      <button>Some button</button>
    </footer>
  </article>
  <article>
    <h2>But this alignment is pretty sweet right?</h2>
    <img src="https://images.unsplash.com/photo-1446776811953-b23d57bd21aa?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTQyNTIwMjN8&ixlib=rb-4.0.3&q=85" alt="" />
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras convallis sodales erat vel accumsan. Nam eget massa nec sem vulputate ullamcorper vel quis justo. Duis rhoncus tempor tempus. Nam eget massa nec sem</p>

    <footer>
      <button>Some button</button>
    </footer>
  </article>
  <article>
    <h2>This is my main title </h2>
    <img src="https://images.unsplash.com/photo-1516339901601-2e1b62dc0c45?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTQyNTIwNDh8&ixlib=rb-4.0.3&q=85" alt="" />
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras convallis sodales erat vel accumsan. Nam eget massa nec sem vulputate ullamcorper vel quis justo. Duis rhoncus tempor tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

    <footer>
      <button>Some button</button>
    </footer>
  </article>
  <article>
    <h2>This is my main title </h2>
    <img src="https://images.unsplash.com/photo-1564053489984-317bbd824340?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTQyNTIwNDh8&ixlib=rb-4.0.3&q=85" alt="" />
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras convallis sodales erat vel accumsan. Nam eget massa nec sem vulputate ullamcorper vel quis justo. Duis rhoncus tempor tempus.</p>

    <footer>
      <button>Some button</button>
    </footer>
  </article>
</section>
              
            
!

CSS

              
                @layer base-styles, theme, layout, subgrid, cards;

@layer subgrid {
  .subgrid-rows {
    &:has(> :nth-child(1):last-child) {
      --subgrid-rows: 1;
    }
    &:has(> :nth-child(2):last-child) {
      --subgrid-rows: 2;
    }
    &:has(> :nth-child(3):last-child) {
      --subgrid-rows: 3;
    }
    &:has(> :nth-child(4):last-child) {
      --subgrid-rows: 4;
    }
    &:has(> :nth-child(5):last-child) {
      --subgrid-rows: 5;
    }
    > * {
      display: grid;
      gap: var(--subgrid-gap, 0);
      grid-row: auto / span var(--subgrid-rows, 5);
      grid-template-rows: subgrid;
    }
  }
}

@layer theme {
  :root {
    --layout-column-min: 400px;
    --layout-gap: 3vmax;
  }
}

@layer layout {
  .grid {
    --grid-min: var(--layout-column-min);
    --grid-gap: var(--layout-gap);
    display: grid;
    grid-template-columns: repeat(
      auto-fit,
      minmax(min(var(--grid-min), 100%), 1fr)
    );
    gap: var(--grid-gap);
  }
  .flex {
    --flex-min: var(--layout-column-min);
    --flex-gap: var(--layout-gap);
    display: flex;
    flex-wrap: wrap;
    gap: var(--flex-gap);
    > * {
      flex: 1 1 var(--flex-min);
    }
  }
  :is(.grid:not(.subgrid-rows), .flex) > * {
    container: var(--grid-item-container, grid-item) / inline-size;
  }

  /* just adding a section max width */
  section {
    width: 100%;
    max-width: 1800px;
    margin-inline: auto;
  }
}

@layer cards {
  article {
    padding: 1.2rem;
    border-radius: 0.5rem;

    background-image: linear-gradient(to top right, #ed00ff 0%, #6000ff 100%);
    color: white;
    @supports (color: color-mix(in oklab, red, tan)) {
      background-image: linear-gradient(
        to top right in oklab,
        oklch(73% 0.5 302) 0%,
        oklch(57% 0.39 276) 100%
      );
    }
    border: 0.3rem solid #6000ff;
    box-shadow: rgba(0, 0, 0, 0.19) 0px 10px 20px,
      rgba(0, 0, 0, 0.23) 0px 6px 6px;
    & img {
      aspect-ratio: 16 / 9;
      object-fit: cover;
      margin-block: 0 1rem;
      border-radius: 0.5rem;
    }
  }

  @container (min-width: 700px) {
    article {
      display: grid;
      grid-template-columns: 1fr 2fr;
      grid-row: auto / span 3;
      gap: 20px;
      & h2 {
        grid-column: 1 / 3;
        margin-block: 0;
      }
      & img {
        grid-row: auto / span 2;
      }
    }
  }
}

@layer base-styles {
  @import url("https://fonts.googleapis.com/css2?family=Lato:wght@300&family=Work+Sans:wght@500&display=swap");
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }
  body {
    margin: 0;
    padding: 5vw;
    display: flex;
    flex-direction: column;
    align-content: center;
    justify-content: center;
    min-height: 100vh;
    font-family: "Lato", sans-serif;
    font-weight: 300;
    font-size: 1.2rem;
    line-height: 1.6;
    background-image: radial-gradient(
      farthest-corner circle at 100% 0%,
      #00009e 0%,
      #27006b 100%
    );
    @supports (color: color-mix(in oklab, red, tan)) {
      background-image: radial-gradient(
        farthest-corner circle at 100% 0% in oklab,
        oklch(22% 0.4 222) 0%,
        oklch(0% 0.5 313) 100%
      );
    }
  }

  p {
    margin-block: 0 1.1rem;
  }

  img {
    max-width: 100%;
    border: none;
  }
  h2 {
    font-family: "Work Sans", sans-serif;
    font-size: 2rem;
    font-weight: 500;
    line-height: 1.2;
    margin-block: 0 1.4rem;
  }
  button {
    --_color: var(--color, black);
    padding: 0.813rem 1.25rem;
    border-radius: 0.313rem;
    font-family: "Lato", sans-serif;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--_color);
    border: 2px solid var(--_color);
    color: white;
  }

  button:is(:hover, :focus) {
    --color: var(--hoverColor, purple);
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console