To center a div in CSS you can use the following snippet.

Sample CSS

#divID {
	width: 300px; /* width you need */
	height: 150x; /* height you need */
	position:absolute;
	left:50%;
	top:50%;
	margin-left:-150px; /* half the width */
	margin-top:-75px; /* half the height */
}

2 thought on “How to center a div in CSS”

Leave a Reply