SyntaxStudy
Sign Up
CSS justify-content & align-items
CSS Beginner 1 min read

justify-content & align-items

justify-content & align-items

justify-content (main axis)

ValueDescription
flex-startPack items to the start (default)
flex-endPack to the end
centerCenter items
space-betweenEven gaps between items, no edge gap
space-aroundEven gaps around items
space-evenlyPerfectly equal gaps everywhere

align-items (cross axis)

ValueDescription
stretchStretch to fill container (default)
centerCenter on cross axis
flex-startAlign to start
flex-endAlign to end
💡 Perfect centering: justify-content: center; align-items: center;
Example
/* Perfect center */
.centered {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 300px;
}

/* Navbar: logo left, links right */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
}