🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #81

Vertical Align


Vertical Centering

Vertical centering in CSS can be achieved using modern layout techniques like Flexbox and Grid, or using positioning with transforms.


Center Align with Flexbox

With CSS flexbox you can center elements, both horizontally and vertically, within a flex container.

A flex container with both the justify-content and the align-items properties set to center will align the item(s) in the center (in both axis):

Example

  .center {
  display: flex;
  justify-content: center;

  align-items: center;
  height: 200px;
  border: 3px solid
  green;
}

Center Align with Grid

With CSS grid you can center elements, both horizontally and vertically, within a grid container.

A grid container with the place-items property set to center, will align the item(s) in the center (in both axis).

Example

  .center {
  display: grid;
  place-items: center;
  height: 200px;
  border: 3px solid
  green;
}

Center Align with position and transform

If you deal with elements of unknown or dynamic dimensions, it is a common technique to use position: absolute; combined with transform: translate(); to center an element:

I am vertically and horizontally centered.

Example

.container p {
  margin: 0;

position: absolute;
  top: 50%;

left: 50%;
  transform: translate(-50%, -50%);
}

Tip: You will learn more about the transform property in our 2D Transforms Chapter.

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Vertical Align – FAQs

Quick answers about learning Vertical Align in CSS.

This free note from CodingNow 2.0 explains Vertical Align in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including Vertical Align, is 100% free with no signup required.
With focused practice, most students grasp Vertical Align in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now