What Are CSS place-items and place-content?

CSS layout modules like Flexbox and Grid provide powerful alignment tools, and place-items and place-content serve as shorthand properties designed to streamline how elements and tracks are positioned. Instead of declaring separate rules for vertical and horizontal axes, these shorthands allow developers to set both alignment dimensions in a single line of CSS. Understanding the distinction between aligning individual items inside cells versus distributing total layout content across a container is essential for writing clean, maintainable stylesheets.

Understanding Alignment Dimensions

CSS Box Alignment defines alignment along two primary axes:

Both shorthand properties accept either one or two values:

/* Syntax Structure */
selector {
  property: <align-axis> <justify-axis>;
  /* or */
  property: <both-axes>;
}

The place-items Shorthand

The place-items property combines align-items and justify-items. It specifies how individual items are aligned inside their respective grid areas or flex lines.

/* Shorthand declaration */
.grid-container {
  display: grid;
  place-items: center;
}

/* Equivalent longhand declarations */
.grid-container {
  display: grid;
  align-items: center;
  justify-items: center;
}

Key Behaviors of place-items

The place-content Shorthand

The place-content property combines align-content and justify-content. It determines the distribution and alignment of the entire layout structure (such as grid tracks or flex lines) within the container when the total size of the items is smaller than the container itself.

/* Shorthand declaration */
.container {
  display: flex;
  place-content: center space-between;
}

/* Equivalent longhand declarations */
.container {
  display: flex;
  align-content: center;
  justify-content: space-between;
}

Key Behaviors of place-content

place-items vs. place-content

The choice between place-items and place-content depends on what part of the layout needs positioning:

Using these shorthands eliminates repetitive CSS declarations, reduces file size, and provides a clear, declarative approach to managing multi-directional layouts across modern web applications.