Skip to content

Home

Transform centering

Vertically and horizontally centers a child element within its parent element using CSS transforms.

💬 Note

The fixed height and width of the parent element is for demonstration purposes only.

<div class="parent">
  <div class="child">Centered content</div>
</div>
.parent {
  border: 1px solid #9C27B0;
  height: 250px;
  position: relative;
  width: 250px;
}

.child {
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

More like this

Start typing a keyphrase to see matching snippets.