align elemnts in center css code example

Example 1: center a div in css

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}

Example 2: how to center align the html element in css examples

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

# center text
.center {
  text-align: center;
  
border: 3px solid green;
}

Example 3: 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