how to center an element in html code example

Example 1: css align items vertical center

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

Example 2: centering css elements

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

Example 3: how to center a div element

/*ADD MARGIN auto to left and right*/
.box1{
    width:80%;
    margin:0 auto;
}

Example 4: css text align center

body {
  text-align: center;
}

Example 5: align center css

margin: auto;

Example 6: how to put element in center in html

p {
  text-align: center;
}

Tags:

Css Example