Z-index

Contact Us or call 1-877-932-8228
Z-index

Z-index

The z-index property specifies the stack level of an element on the page compared to other elements in its same flow. It takes a number as a value. The higher an element's z-index, the closer to the user it appears.

Code Sample:

PositioningAndVisibility/Demos/Zindex.html
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
.logo {
	position:absolute;
	font-family:Century;
	font-size:2em;
	font-weight:bold;
	z-index:20;
}
#logo1 {
	left:50px;
	top:50px;
	color:#00f;
}
#logo2 {
	left:52px;
	top:52px;
	color:#f00;
	z-index:10;
}
.box {
	position:absolute;
	height:100px;
	width:100px;
	border:15px solid #000;
}
#box1 {
	left:150px;
	top:150px;
	border-color:#f00;
	z-index:40;
}
#box2 {
	left:185px;
	top:185px;
	border-color:#00f;
	z-index:30;
}
#box3 {
	left:185px;
	top:150px;
	border-color:#060;
	z-index:20;
}
#box4 {
	left:150px;
	top:185px;
	border-color:#f60;
	z-index:10;
}
</style>
<title>CSS Z-Index</title>
</head>
<body>
	<h1>CSS Z-Index</h1>
	<div id="logo1" class="logo">Webucator</div>
	<div id="logo2" class="logo">Webucator</div>
	<div id="box1" class="box"></div>
	<div id="box2" class="box"></div>
	<div id="box3" class="box"></div>
	<div id="box4" class="box"></div>
</body>
</html>

Code Explanation

The above code will render the following results: Results Image

Notice how some div elements sit on top of the others. If you switch their z-index values, they will stack the differently.

Next