Member-only story

Mastering CSS Grid Positioning: A Guide to Justify-Items and Align-Items

CodeByUmar
3 min readNov 19, 2024

CSS Grid is a game-changer for web developers, offering a powerful way to build complex layouts with minimal code. In this post, we’ll dive into two essential properties of CSS Grid: justify-items and align-items, which controls how grid items are positioned within their cells.

Understanding CSS Grid

Before we start, here’s a quick refresher on CSS Grid. Grid is a layout system designed to divide a container into rows and columns, making it easy to align and distribute elements.

Two key properties that handle positioning within grid cells are:

  1. justify-items: Controls horizontal alignment.
  2. align-items: Controls vertical alignment.

1. justify-items: Horizontal Alignment

The justify-items property aligns grid items horizontally within their cells. It has four possible values:

  • start: Aligns items to the left (start of the cell).
  • end: Aligns items to the right (end of the cell).
  • center: Centers items horizontally in the cell.
  • stretch: Stretches items to fill the entire width of the cell.

Code Example

--

--

CodeByUmar
CodeByUmar

Written by CodeByUmar

Full Stack Developer sharing insights on JavaScript, React, and web development. Passionate coder and problem solver exploring new tech. 🚀

No responses yet