Grid Gallery

grid-gallery creates a gallery with CSS Grid. You can use auto-fill or auto-fit to size the columns.


Create Galleries easily with CSS Grid

grid-gallery lets you create a Gallery with CSS grid. It uses auto-fill by default.

index.html
<div class="grid-gallery">
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
</div>
Resize to see this work!

Choose from auto-fill or auto-fit

grid-gallery uses auto-fill by default.

You can change between auto-fit and auto-fill by using the grid-gallery-fit or grid-gallery-fill class.

index.html
<div class="grid-gallery-fit">
<div>...</div>
<div>...</div>
<div>...</div>
</div>
index.html
<div class="grid-gallery-fill">
<div>...</div>
<div>...</div>
<div>...</div>
</div>
Resize to see this work!

Gallery with auto-fill

Gallery with auto-fit

Change the width of each column

You can size each column with --item-width.

index.html
<div class="grid-gallery [--item-width:5rem]">
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
<div>...</div>
</div>
Resize to see this work!

Never worry about grid items exceeding their container

All grid items have a max-width of 100%, so you can set --item-width to your heart’s content without worrying about it being too large.

index.html
<div class="grid-gallery [--item-width:1000px]">
<div>...</div>
<div>...</div>
<div>...</div>
</div>
Resize to see this work!