Center text inside circle

To center our box we use the align-items property to align our item on the cross axis, which in this case is the block axis running vertically. We use justify-content to align the item on the main axis, which in this case the inline axis running horizontally. This method has support for all browsers so use it freely.

.box {
  background-color: #db9195;
  position: relative;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -webkit-align-items: center;
  -ms-flex-align: center;
  align-items: center;
  text-align: center;
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto;

.box span {
  font-weight: 400;
  font-size: 1.4rem;
  color: white;
  text-transform: uppercase;
<div class="box">



Share this blog snippet!

Copy to clipboard

This post is tagged in

#flex #html #css #webdev

Continue next on flex