How to align objects vertically when working with grids in CSS ? Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report CSS grid layout is one of the strongest layout of CSS. The grid layout is 2-D which means it can handle both rows and columns, unlike flexbox which is 1-D. To align objects apply CSS to the parent element which becomes the grid container and the element's child which becomes the items in the grid. Approach: Use the align-content property of CSS grids to vertically align objects. Syntax: align-content: center; Example 1: html <!DOCTYPE html> <html> <head> <style> .gfg { display: grid; /* display is set to grid layout */ height: 400px; align-content: center; /* vertically aligns objects to the center */ grid-template-columns: auto auto auto; grid-gap: 10px; background-color: #4dd599; /* background colour is set */ padding: 10px; } .gfg > div { background-color: rgba(255, 255, 255, 0.8); text-align: center; /* text inside the container is set to center */ padding: 20px 0; font-size: 30px; } </style> </head> <body> <div class="gfg"> <div>Welcome</div> <div>to</div> <div>Geeks</div> <div>for</div> <div>Geeks</div> <div>Start</div> </div> </body> </html> Output: Example 2: html <!DOCTYPE html> <html> <head> <style> .gfg { display: grid; /* display is set to grid layout */ height: 400px; align-content: center; /* vertically aligns objects to the center */ grid-template-columns: auto auto auto; grid-gap: 10px; background-color: #f67280; /* background colour is set */ padding: 10px; } .gfg > div { background-color: rgba(255, 255, 255, 0.8); text-align: center; /* text inside the container is set to center */ padding: 20px 0; font-size: 30px; } </style> </head> <body> <div class="gfg"> <div>Explore</div> <div>the</div> <div>world</div> <div>travel</div> <div>and</div> <div>eat</div> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to align objects vertically when working with grids in CSS ? A ankit0812 Follow Improve Article Tags : Web Technologies CSS CSS-Properties Similar Reads How to Vertically Align Text Within a Div in CSS? Aligning text vertically within a div can enhance the visual appeal of your web design. There are various approaches to achieving vertical alignment using CSS.1. Using line-height PropertyThe line-height property is the easiest and most commonly used approach to align text within a div vertically. T 2 min read How to Vertically Center Text with CSS? Here are three different ways to Vertically center text in CSS. Vertically center text means aligning text to appear in the middle of its container element.1. Using display PropertyWe can use display: flex to make the container as a flexbox and then applying the align-items: center to vertically cen 2 min read How to Vertically Align an Image Inside a Div in CSS ? In this article, we are going to see how we can vertically align an image inside a div. Centering content both vertically and horizontally is one of the most important functions which needs to be done.Below are the approaches to vertically align an image inside a div in CSS: Â Table of ContentUsing C 4 min read How to Set Three Columns in One Particular Row in CSS Grid? Setting up a grid layout with specific columns in CSS can sometimes be a bit challenging, especially if we are new to CSS Grid. It is a powerful tool that helps us to create complex easily. In this article, we are going to learn about different approaches to setting three columns in one particular r 4 min read How to set vertical alignment in Bootstrap ? Setting vertical alignment in Bootstrap refers to the process of positioning elements along the vertical axis within a layout or container. This ensures consistent and visually appealing alignment of content, such as text, images, or buttons, relative to each other or to the container's boundaries. 2 min read Like