Over a million developers have joined DZone.

The Simplest Way To Horizontally And Vertically Center A DIV Using CSS

//to put the 100px * 100px div in the center of the screen, often used for login or thickbox.

.centered_div {
	width: 100px;
	height: 100px;
	position: absolute;
	top: 50%;
	left: 50%;
	margin-left: -50px;       /*half of width*/
	margin-top: -50px;        /*half of height*/
	background: red;

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}