Skip to navigation

Positioning backgrounds

Using the background-position property.


<!DOCTYPE html>
	<meta charset="utf-8">
	<title>Positioning backgrounds</title>
		body {
			font: 14px courier;
			background: #fff;
			color: #000;
			margin: 0;
			padding: 10px;
		p {
			background: #ccc url("/examples/images/opacityBg.gif") no-repeat;
			height: 200px;
			text-align: center;
			margin: 20px;
		code {
			background: white;
			padding: 0 15px 2px;
		#p0 {
			background: none;
			height: auto;

		#p1 {
			background-position: center;
		#p2 {
			background-position: right;
		#p3 {
			background-position: bottom left;
		#p4 {
			background-position: 20px;
		#p5 {
			background-position: 50%;
		#p6 {
			background-position: 75% 25px;
		#p7 {
			background-position: top 99px right 9px;

		#borderCollie {
			background: none;
		#borderCollie a {
			display: block;
			height: 200px;
			background: #ccc url("") center no-repeat;
			transition: background-position .5s;
			text-indent: -999em;
		#borderCollie a:hover {
			background-position: 50% 10px;
	<p id="p0">In addition to <code>background-repeat: no-repeat</code>&hellip;</p>
	<p id="p1"><code>background-position: center;</code></p>
	<p id="p2"><code>background-position: right;</code></p>
	<p id="p3"><code>background-position: bottom left;</code></p>
	<p id="p4"><code>background-position: 20px;</code></p>
	<p id="p5"><code>background-position: 50%;</code></p>
	<p id="p6"><code>background-position: 75% 25px;</code></p>
	<p id="p7"><code>background-position: top 99px right 9px;</code></p>

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


View original