Responsive Background Images - Modern solution?

Hi there,

I have been searching the forums for information on responsive background images. I can see that a few people have made suggestions, but their posts are from 2016 or many years ago.

We use a static full-width image in the header for each service page. We overlay a filter over the image to darken it down with a blue tint and finish with an H1 heading and a small amount of text. Works great on a large-scale desktop, but performs poorly on mobile devices.

I apologise if I have overlooked a solution entirely. I’m hoping somebody can point me in the right direction to provide a modern solution/workaround?

Best Regards

Nick

Use absolutely-positioned image elements, layered by z-index within a relative container.

That lets you have a background image or vdeo, with overlaid elements and responsive positioning across your breakpoints.

Since it’s a regular <img> it also supports responsive image generation.

I usually use object-fit cover with centered positioning as well so that hero aspect ratio changes are more manageable.

1 Like

Hi Michael,

Thanks for coming back to me on this. I really appreciate it.

I’m not sure what; however, I’m doing something wrong…? It scales and suddenly jumps to that width shown in the images. I’ve put them in order.

See the attached images and link.

Hey Nick — the “jump” usually happens when the container’s height is fixed or the background swaps at a breakpoint.
Quick fix pattern that’s very reliable:

  1. Make the wrapper position: relative.

  2. Place an img inside, set position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover.

  3. Keep text/content layered above with z-index.
    If you can share the read-only link, I can point to the exact element and tweak the breakpoints for you.

Hi Nick, on the image, you have object-fit: contain instead of object-fit: cover. Also give the image 100% width and height to ensure it will stretch to fill the space.

Since your parent ( relative ) element is a Container element, you might have some odd CSS to contend with but you should be ok.

Remember that the Container height either needs to be set, or let the content dictate how tall the section will be.

Hi guys,

Thank you so much for the help you have given me. I’ve applied the setting you have suggested and it all works perfectly!

Kind regards

Nick

1 Like