CSS Center Align

CSS Center Align

.center {
  margin: auto;
  width: 50%;
  border: 3px solid green;
  padding: 10px;
}
//to just center the text inside an element, use text-align: center;

.center {
  text-align: center;
  border: 3px solid green;
}
//to center an image, set left and right margin to auto and make it into a block element

img {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 40%;
}

To horizontally center a block element (like <div>), use margin: auto;.

Center aligning has no effect if the width property is not set (or set to 100%).

Related concepts

CSS Center Align — Structure map

Clickable & Draggable!

CSS Center Align — Related pages: