center align image css code example

Example 1: css center image

.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

Example 2: image align center

.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
}

Example 3: center an image

.someclass {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

Example 4: center element in div

/* html */

Centering with CSS

Text-Align Method

Margin Auto Method

Absolute Positioning Method

/* css */ h1, h3 { text-align: center; } .blue-square-container { text-align: center; } .blue-square { background-color: #0074D9; width: 100px; height: 100px; display: inline-block; }

Tags:

Misc Example