Tag background-position

🎯 CSS background-position: Controlling Image Placement with Precision

In web design, position matters—especially when you’re working with background images. Whether you’re showcasing a logo, setting a subtle texture, or aligning a banner image just right, CSS’s background-position property is your go-to for aligning background images exactly where you want them.


🧾 What is background-position?

The background-position CSS property sets the starting position of a background image relative to its background positioning area (as defined by background-origin).

It controls horizontal and vertical alignment of the image within the element.


🧬 Syntax

selector {
background-position: x y;
}

Where:

  • x = horizontal position
  • y = vertical position

✅ Examples

/* Top left corner (default) */
background-position: left top;

/* Center of the element */
background-position: center center;

/* Offset by pixels */
background-position: 20px 40px;

/* Offset by percentage */
background-position: 50% 75%;

/* Keywords and lengths can be mixed */
background-position: right 10px bottom 20px;

🎨 Common Values

ValueDescription
left topTop-left corner (0% 0%)
center centerCenter of the element (50% 50%)
right bottomBottom-right corner (100% 100%)
10px 20pxOffset 10px from the left, 20px from the top
50% 0Centered horizontally, aligned to the top

🧱 How It Works

Background images are placed inside the background positioning area, which is controlled by background-origin. The image’s position is calculated from the top-left corner by default.

If you use percentages, the position is calculated relative to the size of the element and the size of the image.

📏 Percentages

  • 0% = aligned to the starting edge
  • 50% = centered
  • 100% = aligned to the opposite edge

🧪 Practical Example

HTML:

<div class="banner">Welcome</div>

CSS:

.banner {
width: 600px;
height: 300px;
background-image: url('banner.jpg');
background-position: center top;
background-repeat: no-repeat;
background-size: cover;
}

In this example, the image is centered horizontally and aligned to the top of the element.


🌀 Advanced Usage: Layered Backgrounds

You can position multiple background images, each with its own background-position:

div {
background-image: url(icon.png), url(texture.png);
background-position: top left, center center;
}

🔍 Paired Properties

To unlock the full potential of background-position, use it with:

PropertyPurpose
background-sizeResize the image (covercontain, etc.)
background-repeatControl repeating behavior
background-originSet the positioning reference box
background-attachmentFix or scroll the image with the page

✅ Best Practices

  • Use percentages or keywords for flexible, responsive designs.
  • Combine with background-size: cover or contain for image scaling.
  • Use developer tools to visually test positions during development.
  • Test across screen sizes if positioning is critical (e.g. for hero sections).

🔚 Conclusion

The background-position property gives you precision control over where your background images appear. Whether you’re building a minimalist UI or a rich visual layout, this property helps align images beautifully and responsively.

Mastering background-position is key to polished, professional design.