Skip to navigation

Multiple backgrounds

Layering backgrounds inside a single box.


<!DOCTYPE html>
	<meta charset="utf-8">
	<title>Multiple backgrounds</title>
		body {
			font: 14px/1.5 courier, monospace;
			background: white;
			color: black;
			margin: 20px;
		pre, #htmldog {
			background-color: #c72;
			height: 200px;
			margin: 20px 0;
			overflow: auto;
		pre code {
			background: white;
			padding: 2px 10px 4px 0;

		#p0, #htmldog {
			background-image: url("");
		#p1 {
			background-image: url(""), url("");
		#p2 {
			background-image: url(""), url("");
			background-repeat: no-repeat, repeat;
		#p3 {
			background-image: url(""), url("");
			background-repeat: no-repeat, repeat;
			background-position: center;
		#p4 {
			background: url("") center no-repeat, url("");

		#htmldog a {
			display: block;
			height: 200px;
			background: url("") top -15px left -15px, url("") top -15px right -15px, url("") bottom -15px right -15px, url("") bottom -15px left -15px, url("") center;
			background-repeat: no-repeat;
			text-indent: -999em;
			transition: background-position .5s steps(2);
		#htmldog a:hover {
			background-position: top -25px left -25px, top -25px right -25px, bottom -25px right -25px, bottom -25px left -25px, center;
	<h1><a href="">Multiple backgrounds</a></h1>
	<p>Using the <a href=""><code>background-image</code></a> and <a href=""><code>background</code></a> CSS properties.</p>

	<pre id="p0"><code>background-image: url("bg.gif");</code></pre>
	<pre id="p1"><code>background-image: url("circle.png"), url("bg.gif");</code></pre>
	<pre id="p2"><code>background-image: url("circle.png"), url("bg.gif");</code>
<code>background-repeat: no-repeat, repeat;</code></pre>
	<pre id="p3"><code>background-image: url("circle.png"), url("bg.gif");</code>
<code>background-repeat: no-repeat, repeat;</code>
<code>background-position: center;</code></pre>
	<pre id="p4"><code>background: url("circle.png") center no-repeat, url("bg.gif");</code></pre>

	<!-- Link back to HTML Dog: -->
	<p id="htmldog"><a href=""><img src="" alt="HTML Dog"></a></p>


View original