WordPress: Vertically Justify Content in Boxes of Equal Height

Here’s a way to vertically fill and justify content in equal-size boxes using core WordPress blocks and settings. No plugins required.

by 

WordPress Quick Tip: Boxes of Equal Height with Vertically Aligned Content

A regular layout technique in web design is a row of boxes with similar content. Ideally, the content vertically fills the boxes equally.

One way of creating this in WordPress is a Columns block. In its simplest form, the boxes look like the image below. The boxes (Column blocks in WordPress terms) are not the same height.

Row of boxes with similar content. The boxes are not the same height.
Row of boxes with similar content. The boxes are not the same height.

We can make the box heights the same and justify content vertically with the core WordPress Columns block and Stack blocks.

Learn to insert and edit the Columns block here: Columns Block Documentation at WordPress.org

Learn to insert and edit the Stack block here: Stack Block Documentation at WordPress.org

The Set Up

Nest a Stack block in each column as shown below. Put your content blocks inside the Stack block. In this example, each Column block has a background color, and the content inside those blocks is a heading, paragraph, group with a list, paragraph, and button. But the content can be whatever you want.

Columns block
    Column block
        Stack block
            Headline block
            Paragraph block
            Group block
                List
            Paragraph block
            Buttons block
    Column block
        Stack block
            Headline block
            Paragraph block
            Group block
                List
            Paragraph block
            Buttons block   

The example above shows only two of the four columns of this example.

Columns block Settings: Vertical Alignment Set to None

To make all the columns the same height, set the Columns block Vertical Alignment setting to none. You might have to click on the currently selected setting to turn that setting off.

Columns Block, Set vertical alignment to none. Arrow showing where to click.
WordPress bock editor, Columns block vertical alignment setting set to “none”. You might have to click on the currently selected setting to turn that setting off.

But this leaves another design problem. The columns are the same size, but only the one with the most content fills the space. The other columns have space at the bottom.

Row of boxes with similar content. The boxes are the same height, but content doesn't fill the vertical spaces equally.
Row of boxes with similar content. The boxes are the same height, but content doesn’t fill the vertical spaces equally.

Stack Block Justifies Content Vertically

The Stack block can vertically justify its content to fill the vertical space of the column. Put all the content for each column in a Stack block with these settings:

  • Vertical Alignment: Space between
  • Minimum Height: 100%
Stack block, set vertical alignment to Space between.
WordPress bock editor, Stack block, set vertical alignment to “Space between”.
Stack block, set Minimum Height to "100%".
WordPress bock editor, Stack block, set Minimum Height to “100%”.

The result looks like this:

Row of boxes with similar content. The boxes are the same height, and content fills the vertical spaces equally.
Row of boxes with similar content. The boxes are the same height, and content fills the vertical spaces equally.

Odd Spacing with Content of Significantly Different Heights

I found this technique produces odd spacing when the content of each column has significantly different heights. In the example below, the content of each column is nested like this:

Stack block
    Headline block
    Paragraph block
    List block

Each list has a different number of items, so they are different heights. The spacing between the inner blocks doesn’t work very well.

Row of boxes with content of differing heights has odd vertical spacing between blocks.
Row of boxes with content of differing heights results in odd vertical spacing between blocks.

To fix the spacing, you can change the height of the content blocks manually. In this case, increasing the top margins of each list item improves the spacing.

Row of boxes with content of differing heights improved by manually adjusting the height of the content blocks.
Row of boxes with content of differing heights is improved by manually adjusting the height of the content blocks.

Conclusion

You can vertically justify content in a row of boxes with WordPress core blocks. Use a Columns block for the boxes. Put box content in Stack blocks with Vertical alignment set to “Space between” and Minimum Height set to “100%”.


Comments and Contact Us

If this helps, or you have a question or comment, please send us a message. We don’t have comments on because… you know… spammers. But we’d love to hear from you.

Send us a message if you have a comment.

Dave Loebig

More About Dave Loebig