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

              
                <aside>
  <p>    
    Markup and images 
    taken from an excellent
    <a href="https://codepen.io/jensimmons/pen/QWjqbJj">masonry demo</a>
    by Jen Simmons.
  </p>
</aside>

<main>
  <figure is-tall="more"><figcaption>1</figcaption><img src="https://images.unsplash.com/photo-1587383378486-83d683d9d02d?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-short><figcaption>2</figcaption><img src="https://images.unsplash.com/photo-1588395856595-235a6a1ccca8?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall><figcaption>3</figcaption><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/10558/photo-1587825027984-c4476461c8f9.jpg"></figure>
  <figure><figcaption>4</figcaption><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/10558/photo-1588503391289-5f7b28258022.jpg"></figure>
  <figure is-tall="more"><figcaption>5</figcaption><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/10558/photo-1586603234056-2158d916b705.jpg"></figure>
  <figure><figcaption>6</figcaption><img src="https://images.unsplash.com/photo-1587462829651-7fd0208d766e?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall><figcaption>7</figcaption><img src="https://images.unsplash.com/photo-1585652505968-6266ecf26133?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall><figcaption>8</figcaption><img src="https://images.unsplash.com/photo-1586450463118-8d0cddab713f?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-short><figcaption>9</figcaption><img src="https://images.unsplash.com/photo-1587993988198-a3d05e119eb0?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall><figcaption>10</figcaption><img src="https://images.unsplash.com/photo-1587750059642-d55dfc265acd?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall><figcaption>11</figcaption><img src="https://images.unsplash.com/photo-1586692283466-6e08f395f627?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure><figcaption>12</figcaption><img src="https://images.unsplash.com/photo-1586796105950-b885786d8597?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall><figcaption>13</figcaption><img src="https://images.unsplash.com/photo-1587169544748-d21bd810f57e?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-short><figcaption>14</figcaption><img src="https://images.unsplash.com/photo-1586943101559-4cdcf86a6f87?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure><figcaption>15</figcaption><img src="https://images.unsplash.com/photo-1586767451503-204b55047cb2?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall="more"><figcaption>16</figcaption><img src="https://images.unsplash.com/photo-1586754102101-36b67e4c5bcf?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall><figcaption>17</figcaption><img src="https://images.unsplash.com/photo-1585791022456-be89ddf09c75?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-short><figcaption>18</figcaption><img src="https://images.unsplash.com/photo-1587063749684-d4926a4fc233?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-short><figcaption>19</figcaption><img src="https://images.unsplash.com/photo-1586695940356-4b1c61eabbc7?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-short><figcaption>20</figcaption><img src="https://images.unsplash.com/photo-1587151711096-23c51f92c920?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall="more"><figcaption>21</figcaption><img src="https://images.unsplash.com/photo-1587068786187-db37681155f8?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-short><figcaption>22</figcaption><img src="https://images.unsplash.com/photo-1585841960320-f70aa9b7da69?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall="more"><figcaption>23</figcaption><img src="https://images.unsplash.com/photo-1586968099622-45379e907f32?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-short><figcaption>24</figcaption><img src="https://images.unsplash.com/photo-1588046883141-44883b3c0f15?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
  <figure is-tall><figcaption>25</figcaption><img src="https://images.unsplash.com/photo-1587061966530-a50125ba8512?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"></figure>
</main>

<footer>
  <p>
  This is an experiment.
  I'm trying to approximate a masonry layout
  using a standard grid
  and some rough aspect attributes
  on the elements, e.g.
  <code>is-tall</code> and <code>is-short</code>.
  I'm surprised how well it works,
  but it's not a reliable solution
  unless you know the rough ratio of each box —
  and it's not clever about maintaining equal columns.
  </p>
</footer>
              
            
!

CSS

              
                
main {
  display: grid;
  gap: 10px;  
  grid-template-columns: repeat(auto-fit, minmax(10em, 1fr));
  grid-template-rows: masonry;
}

figure {
  margin: 0;
  grid-row-end: span var(--span, 11);
  
  &[is-short] { --span: 7; }
  &[is-tall] { --span: 13; }
  &[is-tall=more] { --span: 17; }
}

img {
  block-size: auto;
  inline-size: 100%;
}

figcaption {
  background: #333;
  border-radius: 3px 3px 0 0;
  font-family: sans-serif;
  font-size: var(--text-small);
  padding: 3px 1ch;
}






/* from https://codepen.io/miriamsuzanne/pen/RwdpedN */
@layer reset, props, base;

@layer base {
  html {
    font-family: var(--serif);
    color-scheme: light dark;
  }
  
  body {    
    font-size: var(--text-normal);
    padding: var(--gap);
  }

  code:not(pre *) {
    background: linear-gradient(
      -80deg,
      transparent 0.5ch,
      var(--pink-bg) 0.5ch calc(100% - 0.5ch),
      transparent calc(100% - 0.5ch)
    ) no-repeat 0 1ex;
    text-shadow: 2px 2px 0 Canvas;
  }
}

@layer props {
  html {
    /* from https://modernfontstacks.com/ */
    /* old style, industrial, slab */
    --serif: 'Iowan Old Style', 'Palatino Linotype', 'URW Palladio L', P052, serif;
    --sans: Bahnschrift, 'DIN Alternate', 'Franklin Gothic Medium', 'Nimbus Sans Narrow', sans-serif-condensed, sans-serif;
    --slab: Rockwell, 'Rockwell Nova', 'Roboto Slab', 'DejaVu Serif', 'Sitka Small', serif;
  }
  
  body {
    --text-small: clamp(0.938rem, 0.824rem + 0.568cqi, 1.25rem);
    --text-normal: clamp(1.25rem, 1.023rem + 1.136cqi, 1.875rem);
    --text-large: clamp(1.35rem, 0.818rem + 2.659cqi, 2.813rem);
    --text-xlarge: clamp(1.7rem, 0.784rem + 4.58cqi, 4.219rem);
    --gap: clamp(2cqi, 0.5lh, 5cqi);
  }
}

@layer reset {
  * { box-sizing: border-box; }
  html { block-size: 100%; }
  body { margin: unset; }
  
  h1, h2, h3, h4, h5, h6 {
    text-wrap: balance;
  }
  
  p, li {
    text-wrap: pretty;
  }
  
  picture { display: contents; }
  img { display: block; }

  img,
  svg {
    max-inline-size: 100%;
    block-size: auto;
  }
    
  input,
  button,
  textarea,
  select {
    font: inherit;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console