mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4
1129 words
6 minutes
Image Gallery Grid: Syntax and Complete Examples
2026-07-13

:::grid is the blog’s image gallery container directive. It arranges ordinary Markdown images in a responsive grid with a consistent aspect ratio and automatically enables lightbox viewing. Use it for article images, screenshots, portfolios, or small albums.

Images in the same gallery use the same card ratio. By default, center cropping fills every card and keeps each row tidy; clicking an image opens the complete original in a lightbox. Every gallery has its own lightbox group and does not mix with other images in the post.

This post is both feature documentation and a visual test page. View the examples at desktop, tablet, and mobile widths, then click any image to verify lightbox grouping.

Minimal Syntax#

Write Markdown images directly between :::grid and the closing ::::

:::grid
![Image description](./image-1.webp)
![Image description](./image-2.webp)
:::

Each image must occupy its own paragraph, with a blank line between images. Keep only images in a gallery; write paragraphs, lists, and code blocks outside the container.

Here is the result of the minimal syntax. Without parameters, the grid uses three columns, a 16/10 ratio, and cover by default.

Minimal syntax result: first image
Minimal syntax result: first image
Minimal syntax result: second image
Minimal syntax result: second image

Parameters at a Glance#

Write all parameters in braces after the opening directive: :::grid{parameter="value"}.

ParameterAllowed valuesDefaultPurpose
columnsIntegers from 1 to 63Number of columns per row on desktop. Invalid values fall back to 3.
aspectA positive ratio, such as 16/9, 3/4, or 1/116/10The displayed card ratio, not the original image ratio.
fitcover, containcoverImage fitting mode. cover crops to fill; contain preserves the complete image and may leave empty space.

Complete example:

:::grid{columns="3" aspect="16/9" fit="cover"}
![First image](./image-1.webp "Optional caption")
![Second image](./image-2.webp "Optional caption")
![Third image](./image-3.webp "Optional caption")
:::

The following result uses the three-column landscape syntax above. Compare the card ratio, column count, and the way a title takes precedence over alt text as the caption:

Parameter example: first landscape image
Landscape caption 1
Parameter example: second landscape image
Landscape caption 2
Parameter example: third landscape image
Landscape caption 3

Captions and Alt Text#

An image’s alt text serves both as accessible alternative text and as its default caption. When an image has an optional title, the title is used as the caption instead:

![Text used for accessibility](./image.webp "Caption shown below the image")

In the same row, captions align to the bottom of every card. A wrapping caption does not make the others float at a different height. Ratio text such as 3:4 and 16:9 can be written directly in body text, headings, and alt text without escaping.

This example demonstrates the default alt-text caption, an explicit title caption, and bottom alignment for a longer caption:

This image has no title, so its alt text is the caption
This image has no title, so its alt text is the caption
Second square image with accessible alt text
This title is displayed as the caption
Accessible description of a 3:4 poster
This is a longer caption for checking that every caption remains aligned to the bottom of its card when it wraps

Layout and Cropping#

Desktop layouts use the number of columns specified by columns. Below 768px, grids use at most two columns; below 480px, they switch to one column. The card wrapper fixes the aspect ratio and clips rounded corners, while the image fills the card without the theme’s default image margins.

  • Choose cover: the recommended default. Images are cropped from the center to fill the card, making the gallery look consistent.
  • Choose contain: the full original image is shown without cropping. When its ratio differs from the card, the theme background remains visible; use this for images that cannot be cropped.
  • To preserve the complete image without empty space, set aspect close to the original image ratio or place the image in a grid of its own.

The following examples place the same portrait images in 16/9 cards with cover and contain. The first crops them; the second preserves the full image and leaves background space.

:::grid{columns="3" aspect="16/9" fit="cover"}
![Image description](./image-1.webp "Optional caption")
![Image description](./image-2.webp "Optional caption")
:::
:::grid{columns="3" aspect="16/9" fit="contain"}
![Image description](./image-1.webp "Optional caption")
![Image description](./image-2.webp "Optional caption")
:::
First cover result
Cover: center crop
Second cover result
Cover: fill the card
Third cover result
Cover: a more consistent layout
First contain result
Contain: preserve the complete original
Second contain result
Contain: empty space may appear
Third contain result
Contain: suitable for edge details

Default Configuration#

Without attributes, the default is three columns, a 16/10 ratio, and cover cropping. These three portrait images verify default cropping and captions.

:::grid
![Image description](./image-1.webp)
![Image description](./image-2.webp)
![Image description](./image-3.webp)
:::
Default configuration: portrait image one
Default configuration: portrait image one
Default configuration: portrait image two
Default configuration: portrait image two
Default configuration: portrait image three
Default configuration: portrait image three

Three-Column Portraits: 3:4#

With aspect="3/4", the three portrait images fill consistently proportioned vertical cards. If an original image has a different ratio, cover crops its edges from the center.

:::grid{columns="3" aspect="3/4"}
![Portrait image description](./portrait-1.webp)
![Portrait image description](./portrait-2.webp)
![Portrait image description](./portrait-3.webp)
:::
3:4 test image one
Portrait 1
3:4 test image two
Portrait 2
3:4 test image three
Portrait 3

Three-Column Landscapes: 16:9#

This set demonstrates a common video-cover ratio in a three-column layout. Cropping is minimal when the landscape images are close to the card ratio.

:::grid{columns="3" aspect="16/9"}
![Landscape image description](./landscape-1.webp)
![Landscape image description](./landscape-2.webp)
![Landscape image description](./landscape-3.webp)
:::
16:9 test image one
16:9 test image one
16:9 test image two
16:9 test image two
16:9 test image three
16:9 test image three

Two-Column Squares: 1:1#

Two columns work well when larger preview cards are needed. The third image moves to the next row. The final row keeps its grid-track width instead of stretching images to fill the row.

:::grid{columns="2" aspect="1/1"}
![Square image description](./square-1.webp)
![Square image description](./square-2.webp)
![Square image description](./square-3.webp)
:::
1:1 test image one
1:1 test image one
1:1 test image two
1:1 test image two
1:1 test image three
1:1 test image three

Four Columns with contain#

fit="contain" does not crop the original image. When the image ratio differs from the card ratio, the theme background remains visible. This is intentional, not a layout issue. It also verifies that four-column grids and separate lightbox groups do not interfere with each other.

:::grid{columns="4" aspect="16/9" fit="contain"}
![Image description](./image-1.webp)
![Image description](./image-2.webp)
![Image description](./image-3.webp)
:::
Contain: portrait image one
Contain: portrait image one
Contain: portrait image two
Contain: portrait image two
Contain: portrait image three
Contain: portrait image three

Single-Column Detail Image#

One column is suitable when an image needs a larger reading size. It remains one column on desktop, tablet, and mobile, and the original is still available in the lightbox.

:::grid{columns="1" aspect="16/9"}
![Image description](./detail.webp)
:::
Single-column test image
Single-column test image

Sparse Five-Column Row#

Five columns verify a higher supported column count. With only three images, the final row remains left-aligned instead of stretching the images.

:::grid{columns="5" aspect="1/1"}
![Thumbnail description](./thumb-1.webp)
![Thumbnail description](./thumb-2.webp)
![Thumbnail description](./thumb-3.webp)
:::
Five-column test image one
Five-column test image one
Five-column test image two
Five-column test image two
Five-column test image three
Five-column test image three

Mixed Images in Six Columns#

Six columns are the current maximum. Mixing landscape and portrait images verifies cover cropping, captions on narrow cards, and a dense desktop layout. For readable article content, two to four columns are usually preferable.

:::grid{columns="6" aspect="1/1"}
![Image description](./image-1.webp)
![Image description](./image-2.webp)
![Image description](./image-3.webp)
![Image description](./image-4.webp)
![Image description](./image-5.webp)
![Image description](./image-6.webp)
:::
Six-column test image one
Six-column test image one
Six-column test image two
Six-column test image two
Six-column test image three
Six-column test image three
Six-column test image four
Six-column test image four
Six-column test image five
Six-column test image five
Six-column test image six
Six-column test image six

Four-Column Squares: 1:1#

Four square images with the same ratio are a typical four-column layout. Desktop displays all four in one row; tablet collapses to two columns and mobile to one.

:::grid{columns="4" aspect="1/1"}
![Square image description](./square-1.webp)
![Square image description](./square-2.webp)
![Square image description](./square-3.webp)
![Square image description](./square-4.webp)
:::
Square image one
Square image one
Square image two
Square image two
Square image three
Square image three
Square image four
Square image four

Six-Column Landscapes: 16:9#

Six landscape columns work well for thumbnail previews, portfolios, and screenshot indexes. Even if original ratios differ slightly, cover fills every 16/9 card consistently.

:::grid{columns="6" aspect="16/9"}
![Landscape image description](./landscape-1.webp)
![Landscape image description](./landscape-2.webp)
![Landscape image description](./landscape-3.webp)
![Landscape image description](./landscape-4.webp)
![Landscape image description](./landscape-5.webp)
![Landscape image description](./landscape-6.webp)
:::
Landscape image one
Landscape image one
Landscape image two
Landscape image two
Landscape image three
Landscape image three
Landscape image four
Landscape image four
Landscape image five
Landscape image five
Landscape image six
Landscape image six

Three-Column Portraits: 3:4#

This group of six portrait images demonstrates a common layout for people, posters, or mobile screenshots. The images form two rows of three, with captions aligned to the bottom.

:::grid{columns="3" aspect="3/4"}
![Portrait image description](./portrait-1.webp)
![Portrait image description](./portrait-2.webp)
![Portrait image description](./portrait-3.webp)
![Portrait image description](./portrait-4.webp)
![Portrait image description](./portrait-5.webp)
![Portrait image description](./portrait-6.webp)
:::
Portrait image one
Portrait image one
Portrait image two
Portrait image two
Portrait image three
Portrait image three
Portrait image four
Portrait image four
Portrait image five
Portrait image five
Portrait image six
Portrait image six

Edge-Critical Content: cover and Lightbox#

These images contain important text or details near their edges. cover keeps the grid tidy but may crop those edges; click an image to view the uncropped original in the lightbox. Use clear captions for edge-sensitive images, or use contain below.

:::grid{columns="3" aspect="16/9" fit="cover"}
![Edge-critical content](./critical-1.webp "Open the lightbox to view the complete edge content")
![Edge-critical content](./critical-2.webp "Open the lightbox to view the complete edge content")
![Edge-critical content](./critical-3.webp "Open the lightbox to view the complete edge content")
:::
First edge-critical image
Open the lightbox to view the complete edge content
Second edge-critical image
Open the lightbox to view the complete edge content
Third edge-critical image
Open the lightbox to view the complete edge content

Extreme Ratios with contain#

For banners, long screenshots, and other extreme image ratios, contain displays the complete original. Unlike cover, it may leave theme-background space, but it never crops content.

:::grid{columns="3" aspect="16/9" fit="contain"}
![Complete screenshot description](./wide-1.webp)
![Complete screenshot description](./wide-2.webp)
![Complete screenshot description](./wide-3.webp)
:::
Extreme-ratio image one
Extreme-ratio image one
Extreme-ratio image two
Extreme-ratio image two
Extreme-ratio image three
Extreme-ratio image three

Transparent Images#

Transparent images reveal the card’s theme background. This single-column contain example makes the transparent areas, original edges, and lightbox behavior easy to inspect.

:::grid{columns="1" aspect="16/9" fit="contain"}
![Transparent image description](./transparent.webp)
:::
Transparent-background test image
Transparent-background test image

Click any image in a grid to open the Fancybox lightbox. There you can zoom, rotate, enter fullscreen, view thumbnails, and navigate with the arrow keys. Navigation is limited to the current :::grid container: for example, clicking “16:9 test image one” only opens the other two landscape images in that section.

Ordinary Markdown images in the same post continue to be handled separately; they are not added to any grid gallery.

Checklist#

  1. Images in each grid have consistent dimensions, with captions below the cards.
  2. Images scale slightly on hover; after clicking, they can be zoomed, rotated, and navigated with the keyboard.
  3. Clicking “16:9 test image one” lets the lightbox browse only the other two landscape images in that section.
  4. Below 768px, grids use at most two columns; below 480px, they use one column.
  5. Portrait images in “Four Columns with contain” are fully visible with empty space and no cropping.
  6. Five- and six-column grids retain their specified column count on wide screens, then collapse to two or one column according to the responsive rules.
Share

If this article helped you, please share it with others!

Image Gallery Grid: Syntax and Complete Examples
https://mizuki.mysqil.com/posts/image-grid-demo/
Author
まつざか ゆき
Published at
2026-07-13
License
CC BY-NC-SA 4.0

Some information may be outdated

Table of Contents