# Display side by side image grid

**URL:** <https://forum.obsidian.md/t/display-side-by-side-image-grid/9359>\
**Category:** Themes & CSS snippets\
**Tags:** custom-css\
**Created:** [December 2, 2020, 1:31am UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359 "2020-12-02T01:31:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kepano](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kepano/32/23113_2.png) [@kepano](https://forum.obsidian.md/u/kepano)\
**Post date:** [December 2, 2020, 1:31am UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/1 "2020-12-02T01:31:16Z")

</div>

## Updated 2021-12-22

This functionality is now available in [Minimal Theme](https://github.com/kepano/obsidian-minimal) combined with Contextual Typography v2.2.1 — read the [Minimal 4.2 release notes](https://github.com/kepano/obsidian-minimal/releases/tag/4.2.0) for more detail.

Documentation for Image Grids can be found here:

> **[Image grids - Minimal Documentation](https://minimal.guide/Block+types/Image+grids)**
>
> Image grids - Minimal Documentation

* * *

## Archived post (before Obsidian v0.11.3)

A simple snippet that you can pair with the new `cssclass` YAML code (as of 0.9.19). Add `cssclass: img-grid` to your front matter to display images in columns. Pairs nicely with [Image zoom: click + hold to expand images](https://forum.obsidian.md/t/image-zoom-click-hold-to-expand-images/5164)

### Saving the snippet (0.9.19+)

Save this snippet as `img-grid.css` and add it to `.obsidian/snippets` folder in your vault. You can then turn it on from the Appearance settings.

```auto
/* Updated for Obsidian 0.9.22 and up */

.img-grid .markdown-preview-section img:not([width]),
.img-grid .markdown-preview-section video {
    width:100%;
}
.img-grid .markdown-preview-section > div {
    display:flex;
}
.img-grid .markdown-preview-section > div > .internal-embed {
    flex:1;
    margin-left:-0.5rem;
    padding:0 0.5rem 0.5rem 0.5rem;
}
.img-grid .markdown-preview-section > div > *:not(div) {
    margin-block-start: 0rem;
    margin-block-end: 1rem;
}
.img-grid .markdown-preview-section > div hr {
    width:100%;
}
/* These lines make every image the same height */
.img-grid .markdown-preview-section > div > .internal-embed img:not(:active) {
    object-fit:cover;
    height:100%;
}

```

### Usage

In edit mode, add `cssclass: img-grid` to your frontmatter. Then simply group your images by adding an extra line break between each row. The code will automatically create equal size columns for each image.

 ![Screen Shot 2020-12-01 at 5.01.12 PM](https://forum.obsidian.md/uploads/default/original/2X/6/6c48387be6edc78aa9a8eedce6d6acec7e10ff56.jpeg)

### Demo

This is paired with [Image zoom: click + hold to expand images](https://forum.obsidian.md/t/image-zoom-click-hold-to-expand-images/5164)

[https://dl.dropboxusercontent.com/s/1nm6tq9s6d8tlai/img-grid.mp4?dl=0](https://dl.dropboxusercontent.com/s/1nm6tq9s6d8tlai/img-grid.mp4?dl=0)

---

<div class="post-metadata">

**Author:** ![kepano](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kepano/32/23113_2.png) [@kepano](https://forum.obsidian.md/u/kepano)\
**Post date:** [December 2, 2020, 3:34am UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/2 "2020-12-02T03:34:38Z")

</div>

### Alternative with even height columns

If you would like the images in each cell to be the same height add these extra lines of code. Note that this will crop the image a bit if they are not all the same aspect ratio.

```auto
/* For Obsidian 0.9.22 and up */
/* These lines make every image the same height */
.img-grid .markdown-preview-section > div > .internal-embed img:not(:active) {
    object-fit:cover;
    height:100%;
}

```

 ![Screen Shot 2020-12-01 at 7.34.02 PM](https://forum.obsidian.md/uploads/default/original/2X/7/7659ffb27ce45b310ad516bd70ca095d635f8df6.jpeg)

---

<div class="post-metadata">

**Author:** ![Klaas](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Klaas](https://forum.obsidian.md/u/Klaas)\
**Post date:** [December 2, 2020, 6:33am UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/3 "2020-12-02T06:33:30Z")

</div>

Nice house you got there 👌

---

<div class="post-metadata">

**Author:** ![Klaas](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Klaas](https://forum.obsidian.md/u/Klaas)\
**Post date:** [December 2, 2020, 6:15pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/4 "2020-12-02T18:15:50Z")

</div>

In a note with images and blockquotes, not only the images are placed in a grid, but so are the blockquotes. How can that be avoided?

---

<div class="post-metadata">

**Author:** ![kepano](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kepano/32/23113_2.png) [@kepano](https://forum.obsidian.md/u/kepano)\
**Post date:** [December 2, 2020, 8:21pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/5 "2020-12-02T20:21:32Z")

</div>

You would need to add an extra line break between block quotes.

Unfortunately there isn’t a CSS selector that can detect the contents of each paragraph section.

Edit: are you running the latest version of the code? I made some small tweaks. If you can share an example of what you see in edit and preview that could help.

---

<div class="post-metadata">

**Author:** ![Klaas](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Klaas](https://forum.obsidian.md/u/Klaas)\
**Post date:** [December 3, 2020, 3:49am UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/6 "2020-12-03T03:49:48Z")

</div>

Edit and Preview

 ![grid](https://forum.obsidian.md/uploads/default/original/2X/5/59b22d96c73ab11c9b1b7a0cdcdb57dbc01a211c.png)

 ![grid2](https://forum.obsidian.md/uploads/default/original/2X/2/2992da54defbde6665664f22ca3da6055b5e873a.jpeg)

---

<div class="post-metadata">

**Author:** ![kepano](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kepano/32/23113_2.png) [@kepano](https://forum.obsidian.md/u/kepano)\
**Post date:** [December 3, 2020, 6:47am UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/7 "2020-12-03T06:47:40Z")

</div>

The issue here is using the `<br>` tags because Obsidian will interpret those as elements in the same text block. You have to separate them without the HTML

---

<div class="post-metadata">

**Author:** ![Klaas](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Klaas](https://forum.obsidian.md/u/Klaas)\
**Post date:** [December 3, 2020, 7:13am UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/8 "2020-12-03T07:13:12Z")

</div>

I am confused. You stated before:

> You would need to add an extra line break between block quotes.

To me that means adding `<br>` between blocks. Now you say:

> The issue here is using the   
> tags because Obsidian will interpret those as elements in the same text block. You have to separate them without the HTML

So, please tell me specifically how I should separate them. What code should I use?

---

<div class="post-metadata">

**Author:** ![kepano](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kepano/32/23113_2.png) [@kepano](https://forum.obsidian.md/u/kepano)\
**Post date:** [December 3, 2020, 7:41am UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/9 "2020-12-03T07:41:10Z")

</div>

None, just a blank empty line.

---

<div class="post-metadata">

**Author:** ![Klaas](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Klaas](https://forum.obsidian.md/u/Klaas)\
**Post date:** [December 3, 2020, 7:47am UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/10 "2020-12-03T07:47:38Z")

</div>

Wow, that was simple, it works fine now.  
Thanks a lot for a very useful plug-in.

---

<div class="post-metadata">

**Author:** ![feva](https://forum.obsidian.md/user_avatar/forum.obsidian.md/feva/32/6417_2.png) [@feva](https://forum.obsidian.md/u/feva)\
**Post date:** [December 3, 2020, 1:34pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/11 "2020-12-03T13:34:47Z")

</div>

This is awesome! Thank you very much for both snippets

---

<div class="post-metadata">

**Author:** ![feva](https://forum.obsidian.md/user_avatar/forum.obsidian.md/feva/32/6417_2.png) [@feva](https://forum.obsidian.md/u/feva)\
**Post date:** [December 3, 2020, 2:46pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/12 "2020-12-03T14:46:54Z")

</div>

Hmm after playing around with this, the Headings suffer from spacing issues. This is due to the global `display: flex`. If only we could only use the `display: flex` for the `.markdown-preview-section`s that do contain images and nothing else, this would work perfectly.

---

<div class="post-metadata">

**Author:** ![kepano](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kepano/32/23113_2.png) [@kepano](https://forum.obsidian.md/u/kepano)\
**Post date:** [December 3, 2020, 3:40pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/13 "2020-12-03T15:40:11Z")

</div>

I agree with you. It’s not perfect given the limitations of the CSS selectors available. If you want to refine this code, you can add top/bottom margins and padding to headings within the `.img-grid .markdown-preview-section` so that it matches up perfectly.

---

<div class="post-metadata">

**Author:** ![Jeffurry](https://forum.obsidian.md/user_avatar/forum.obsidian.md/jeffurry/32/207_2.png) [@Jeffurry](https://forum.obsidian.md/u/Jeffurry)\
**Post date:** [December 8, 2020, 11:35pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/14 "2020-12-08T23:35:01Z")

</div>

@kepano v0.9.22 seems to have broken your snippet (to my profound distress). The images are no longer previewing, and everything is in columns, kinda…

 ![image](https://forum.obsidian.md/uploads/default/original/2X/e/ef83c42d840bcf66cc25a15131f7a9a14023bd1e.jpeg)  
If you could fix this I would be very grateful.

---

<div class="post-metadata">

**Author:** ![kepano](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kepano/32/23113_2.png) [@kepano](https://forum.obsidian.md/u/kepano)\
**Post date:** [December 9, 2020, 2:58am UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/15 "2020-12-09T02:58:27Z")

</div>

@Jeffurry here’s an updated version:

```auto
/* For Obsidian 0.9.22 and up */

.img-grid .markdown-preview-section img:not([width]),
.img-grid .markdown-preview-section video {
   width:100%;
}
.img-grid .markdown-preview-section > div {
   display:flex;
}
.img-grid .markdown-preview-section > div > .internal-embed {
   flex:1;
   margin-left:-0.5rem;
   padding:0 0.5rem 0.5rem 0.5rem;
}
.img-grid .markdown-preview-section > div > *:not(div) {
   margin-block-start: 0rem;
   margin-block-end: 1rem;
}
.img-grid .markdown-preview-section > div hr {
   width:100%;
}
/* These lines make every image the same height */
.img-grid .markdown-preview-section > div > .internal-embed img:not(:active) {
   object-fit:cover;
   height:100%;
}

```

---

<div class="post-metadata">

**Author:** ![Jeffurry](https://forum.obsidian.md/user_avatar/forum.obsidian.md/jeffurry/32/207_2.png) [@Jeffurry](https://forum.obsidian.md/u/Jeffurry)\
**Post date:** [December 9, 2020, 4:14pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/16 "2020-12-09T16:14:23Z")

</div>

Thanks @kepano, that gets the grid back nicely. Something else is going on though. I suspect it might be unavoidable…but… can be excluded from the elements covered by the snippet, as it is messing with my headings at the top, and the ‘On This Day’ thing someone

 ![image](https://forum.obsidian.md/uploads/default/original/2X/0/0e080cbccaf33372c16c7b9ac388aee5599d6270.png)

 ![image](https://forum.obsidian.md/uploads/default/original/2X/1/17db2d32e7e550a51a2c888b14df3b7c25a1657a.jpeg)

---

<div class="post-metadata">

**Author:** ![kepano](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kepano/32/23113_2.png) [@kepano](https://forum.obsidian.md/u/kepano)\
**Post date:** [December 9, 2020, 4:44pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/17 "2020-12-09T16:44:57Z")

</div>

It might be avoidable by adding extra line breaks (no `<br>` tag just an extra blank line) between the elements that you want on separate rows. This is the same issue as Klaas’ above.

The reason this is happening is that that the snippet naively takes any elements that are in the same text block and puts them side by side. I haven’t figured out a clever way to do this only for images.

---

<div class="post-metadata">

**Author:** ![Jeffurry](https://forum.obsidian.md/user_avatar/forum.obsidian.md/jeffurry/32/207_2.png) [@Jeffurry](https://forum.obsidian.md/u/Jeffurry)\
**Post date:** [December 9, 2020, 4:59pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/18 "2020-12-09T16:59:20Z")

</div>

“naïve code” I love it! Could you explain what this does…

.img-grid .markdown-preview-section img:not([width]),  
.img-grid .markdown-preview-section video {  
width:100%;  
}  
…like, to a six year old. I’d like to learn this stuff a bit, rather than come running to ‘Dad’ every time!

---

<div class="post-metadata">

**Author:** ![kepano](https://forum.obsidian.md/user_avatar/forum.obsidian.md/kepano/32/23113_2.png) [@kepano](https://forum.obsidian.md/u/kepano)\
**Post date:** [December 9, 2020, 5:01pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/19 "2020-12-09T17:01:52Z")

</div>

This code makes images or videos fill the width of their column/cell. You might not notice this if you are using large images, but it’s relevant for smaller ones.

It ignores images that have a width explicitly defined by the user which is what the `:not([width])` is for.

---

<div class="post-metadata">

**Author:** ![Jeffurry](https://forum.obsidian.md/user_avatar/forum.obsidian.md/jeffurry/32/207_2.png) [@Jeffurry](https://forum.obsidian.md/u/Jeffurry)\
**Post date:** [December 9, 2020, 5:11pm UTC](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359/20 "2020-12-09T17:11:41Z")

</div>

Thanks - I will have a play. It is probably time I ‘bought you a coffee’ Cheers.

[Next page](https://forum.obsidian.md/t/display-side-by-side-image-grid/9359.md?page=2)
