Last updated: 27 November 2025

Tailwind CSS Background Position

Tailwind Background position controls where your background image sits inside its container. When your image is larger than the container (which happens constantly with responsive design), you need to decide what part of the image stays visible.


Tailwind Background Position

Tailwind Background position controls where your background image sits inside its container. When your image is larger than the container (which happens constantly with responsive design), you need to decide what part of the image stays visible. That's what bg-{position} utilities handle.

Most useful when:

  • Hero images need to show a specific subject (person's face, product, focal point)
  • Card backgrounds should emphasize certain areas
  • Images need different positioning at different screen sizes
  • You're using bg-cover and parts of the image get cropped

How to apply Tailwind Background Position

Tailwind gives you nine options organized like a grid:

html
<!-- Top row -->
<div class="bg-top-left">Top left corner</div>
<div class="bg-top">Top center</div>
<div class="bg-top-right">Top right corner</div>
<!-- Middle row -->
<div class="bg-left">Center left</div>
<div class="bg-center">Dead center (default)</div>
<div class="bg-right">Center right</div>
<!-- Bottom row -->
<div class="bg-bottom-left">Bottom left corner</div>
<div class="bg-bottom">Bottom center</div>
<div class="bg-bottom-right">Bottom right corner</div>

Think of it like a tic-tac-toe board. You're telling Tailwind which square to anchor the image to.

html
<div class="bg-top-left"></div>
<div class="bg-top"></div>
<div class="bg-top-right"></div>

Preview

When Position Actually Matters

It only matters when:

  • Your image is bigger than the container
  • You're using bg-cover (which scales the image to fill the container)
  • The image's aspect ratio doesn't match the container

If your image fits perfectly, position does nothing. You'll mostly use this with hero sections, cards, and responsive layouts where cropping is inevitable.

Combining with bg-cover and bg-contain

Position works differently depending on your sizing strategy:

With bg-cover (most common)

bg-cover scales the image to fill the entire container, cropping whatever doesn't fit. Position decides what gets cropped:

html
<!-- Landscape photo in tall container - top crops off -->
<div class="h-screen bg-cover bg-top bg-[url('/landscape.jpg')]">
Shows top of image, bottom gets cropped
</div>
<!-- Same photo, different position - bottom stays -->
<div class="h-screen bg-cover bg-bottom bg-[url('/landscape.jpg')]">
Shows bottom of image, top gets cropped
</div>

With bg-contain (less common)

bg-contain scales the image to fit entirely inside the container, leaving empty space. Position decides where that empty space appears:

html
<!-- Image sits in top-left, empty space bottom-right -->
<div class="h-96 bg-contain bg-top-left bg-no-repeat bg-[url('/logo.jpg')]">
</div>
<!-- Image centered, empty space around it -->
<div class="h-96 bg-contain bg-center bg-no-repeat bg-[url('/logo.jpg')]">
</div>

I rarely use bg-contain for photos, it's better for logos or icons where you want the full image visible.

Responsive Positioning Patterns

Pattern 1: Focus Shift

Show different parts of an image at different sizes:

html
<!-- Mobile: show top (where the product is) -->
<!-- Desktop: show center (full scene) -->
<div class="h-64 md:h-96 bg-cover bg-top md:bg-center bg-[url('/product-scene.jpg')]">
</div>

Pattern 2: Portrait to Landscape

When your image orientation doesn't match your layout:

html
<!-- Tall container on mobile (portrait) -->
<!-- Wide container on desktop (landscape) -->
<div class="h-screen md:h-64 bg-cover bg-center md:bg-left bg-[url('/team-photo.jpg')]">
</div>

Pattern 3: Adaptive Cards

Grid of cards where each needs different focal points:

html
<div class="grid md:grid-cols-3 gap-4">
<div class="h-48 bg-cover bg-center bg-[url('/card1.jpg')]">
<div class="p-4 text-white">Card 1</div>
</div>
<div class="h-48 bg-cover bg-right bg-[url('/card2.jpg')]">
<div class="p-4 text-white">Card 2</div>
</div>
<div class="h-48 bg-cover bg-left bg-[url('/card3.jpg')]">
<div class="p-4 text-white">Card 3</div>
</div>
</div>

Each card can position its background independently based on what part of the image matters.

Arbitrary Position Values

Need more control? Use arbitrary values:

html
<!-- Position at specific percentage -->
<div class="bg-position-[center_top_25%]">25% from top</div>
<!-- Exact pixel positioning -->
<div class="bg-position-[50px_100px]">50px right, 100px down</div>
<!-- Combine keywords and values -->
<div class="bg-position-[left_20%]">Left aligned, 20% from top</div>

I rarely need these, but they're useful when you have an image where the focal point is off-center in a weird way.

Background Images vs Image Tags

Here's where people get confused:

Background images (what we're talking about):

html
<div class="bg-cover bg-center bg-[url('/image.jpg')]"></div>

Image tags (different positioning system):

html
<img src="/image.jpg" class="object-cover object-center" />

They look similar but use different utilities:

  • Background images: bg-{position}, bg-cover, bg-contain
  • Image tags: object-{position}, object-cover, object-contain

Use background images when:

  • The image is decorative (not content)
  • You need overlays or text on top
  • You're building hero sections or cards

Use <img> tags when:

  • The image is content (needs alt text for accessibility)
  • You need lazy loading
  • Search engines should index it

Common Mistakes

  • Not setting a height:
html
html<!-- Won't show anything - no height -->
<div class="bg-cover bg-center bg-[url('/image.jpg')]"></div>
<!-- Fixed -->
<div class="h-96 bg-cover bg-center bg-[url('/image.jpg')]"></div>

Background images need explicit height. They won't push the container open like <img> tags do.

  • Forgetting bg-cover or bg-contain:
html
<!-- Image repeats and looks weird -->
<div class="h-96 bg-center bg-[url('/image.jpg')]"></div>
<!-- Fixed -->
<div class="h-96 bg-cover bg-center bg-[url('/image.jpg')]"></div>

Position alone doesn't scale the image. You almost always want bg-cover or bg-contain too.

  • Using wrong position for image orientation:
html
<!-- Portrait photo in landscape container - crops face -->
<div class="h-64 w-full bg-cover bg-center bg-[url('/portrait.jpg')]"></div>
<!-- Fixed - keeps face visible -->
<div class="h-64 w-full bg-cover bg-top bg-[url('/portrait.jpg')]"></div>

Think about what part of the image matters and position accordingly.

  • Not adding bg-no-repeat:
html
<!-- Small image tiles across container -->
<div class="h-96 bg-top-left bg-[url('/small-logo.jpg')]"></div>
<!-- Fixed -->
<div class="h-96 bg-top-left bg-no-repeat bg-[url('/small-logo.jpg')]"></div>

If your image is smaller than the container and you don't want it repeated, add bg-no-repeat.

  • Ignoring mobile:
html
<!-- Looks great on desktop, broken on mobile -->
<div class="h-screen bg-cover bg-center bg-[url('/wide-image.jpg')]">
<h1 class="text-6xl">Title</h1>
</div>
<!-- Fixed with responsive positioning -->
<div class="h-screen bg-cover bg-top md:bg-center bg-[url('/wide-image.jpg')]">
<h1 class="text-6xl">Title</h1>
</div>

Always test on mobile. What looks centered on desktop might crop important parts on narrow screens.

When to Skip Background Images Entirely

Sometimes you shouldn't use background images at all: Use <img> tags instead when:

  • The image is important content (needs alt text)
  • You need it indexed by search engines
  • You want lazy loading for performance
  • You're building a gallery or portfolio
  • Accessibility is critical (screen readers)

Use CSS Grid or Flexbox when:

  • You're positioning content, not decorating
  • You need responsive layout control
  • Text and images need to reflow together

Background images are great for decoration and hero sections. For everything else, consider whether a real <img> element or layout utility would work better.

Real Case Examples

Full Hero Banner

html
<div class="flex items-center justify-center h-96 bg-[url('/images/hero.jpg')] bg-center bg-cover bg-no-repeat text-white text-3xl font-bold">
Welcome to Our Site
</div>

Preview

Welcome to Our Site

This creates a centered, full-width banner with perfectly positioned background and centered content.

Card with Background Image

html
<div class="relative h-64 bg-cover bg-center bg-[url('/card-bg.jpg')] rounded-lg overflow-hidden">
<div class="absolute inset-0 bg-linear-to-t from-black to-transparent"></div>
<div class="absolute bottom-0 left-0 right-0 p-6 text-white">
<h3 class="text-2xl font-bold mb-2">Card Title</h3>
<p>Card description goes here</p>
</div>
</div>

Preview

Card Title

Card description goes here

Gradient overlay at the bottom makes text readable while keeping the image's focal point visible at the top/center.

Profile Header

html
<div class="h-48 bg-cover bg-center bg-[url('/cover-photo.jpg')]">
<!-- Cover photo background -->
</div>
<div class="relative -mt-16 flex justify-center">
<img src="/avatar.jpg" class="w-32 h-32 rounded-full border-4 border-white" />
</div>

Preview

The bg-center keeps the cover photo balanced while the avatar overlaps at the bottom.

Split Section

html
<div class="grid md:grid-cols-2">
<!-- Left: Image background -->
<div class="h-96 bg-cover bg-center bg-[url('/feature.jpg')]"></div>
<!-- Right: Text content -->
<div class="h-96 flex items-center justify-center bg-gray-100 p-8">
<div>
<h2 class="text-3xl font-bold mb-4">Feature Title</h2>
<p class="text-gray-700">Feature description here</p>
</div>
</div>
</div>

Preview

Feature Title

Feature description here

Image fills left side, text fills right side. Position keeps the image focal point visible in the left panel.

Conclusion

Background position is straightforward once you understand the coordinate system. Pick where you want the image anchored (bg-top, bg-center, etc.), combine it with bg-cover for scaling, and adjust responsively if needed. Test on mobile first. Portrait photos need different positioning than landscape images, and what works on desktop often crops badly on narrow screens. And remember: if the image is content (not decoration), use an <img> tag instead. Background images are for visual enhancement, not primary content.

Tailwind Background Position Class Table

ClassPropertiesDescription
bg-bottombackground-position: bottom;Aligns image to the top center
bg-centerbackground-position: center;Centers the image both ways
bg-leftbackground-position: left; Aligns image to the center left
bg-left-bottombackground-position: left bottom;Aligns image to the bottom center
bg-left-topbackground-position: left top;Top-left alignment
bg-rightbackground-position: right;Aligns image to the center right
bg-right-bottombackground-position: right bottom; Bottom-right alignment
bg-left-bottombackground-position: left bottom;Bottom-left alignment
bg-right-topbackground-position: right top; Top-right alignment
bg-topbackground-position: top;Top alignment

Worth Reading

Windframe Tailwind blocks

Timeline

Windframe is an AI visual editor for rapidly building stunning web UIs & websites

Start building stunning web UIs & websites!

Build from scratch or select prebuilt tailwind templates