how to center an item horizontally html css code example

Example 1: how to align elements horizontally in css

.row {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.block {
  width: 100px;
}

Example 2: centering css elements

// add to the parent element
.parent {
	display: grid;
    place-items: center;
}

Example 3: how to horizontal center a div in css

#inner {
  width: 50%;
  margin: 0 auto;
}

Example 4: how to align elements horizontally in css

<div class="row">
  <div class="block">Lorem</div>
  <div class="block">Ipsum</div>
  <div class="block">Dolor</div>
</div>

Tags:

Html Example