You're probably looking at a hero section, banner, promo block, or popup and thinking the same thing most Divi users think at this point: “I can get the background image in there, but why does it crop weirdly, look dull behind text, or slow the page down?”
That's the problem with the background image of a div. The CSS syntax is simple. The design and performance decisions aren't.
In Divi, it's easy to click a background into a Section or Row and move on. But if you understand the CSS underneath, Divi's controls stop feeling mysterious. You can predict what Cover will do, when Fit is the wrong choice, why text becomes unreadable, and where lazy loading needs custom help instead of wishful thinking.
The CSS Foundation for Div Backgrounds
A background image of a div starts with a single declaration:
.hero {
background-image: url('/images/hero.jpg');
}
That only loads the file. The browser still applies its defaults, so the image anchors to the top-left and repeats unless you tell it otherwise.
For production layouts, I treat background-image as the starting point, not the finished rule. A hero, banner, card, or promo block usually needs four properties working together.
Start with the four properties that matter most
This is the baseline I use on most projects:
.hero {
background-image: url('/images/hero.jpg');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
Each property solves a specific layout problem:
background-imageloads the asset.background-repeat: no-repeatprevents tiling.background-position: center centerkeeps the visual focus closer to the middle of the frame.background-size: coverscales the image so the container is fully filled.
That combination gives you a designed background instead of raw browser behavior.
Practical rule: If you set only
background-image, you have loaded an asset. You have not finished the background.
Shorthand is cleaner once you can read it quickly
The longhand version is easier to learn and debug. After that, shorthand is faster to maintain:
.hero {
background: url('/images/hero.jpg') center center / cover no-repeat;
}
I use shorthand for repeated patterns across sections, blurbs, cards, and call-to-action blocks. It keeps the stylesheet tighter, but only if the team can read it without stopping to decode the order.
Backgrounds need dimensions to show up
A background image does not create height for the element. The div still needs space from content, padding, a fixed height, or a minimum height.
.hero {
min-height: 500px;
background: url('/images/hero.jpg') center center / cover no-repeat;
}
Or:
.promo-banner {
padding: 80px 40px;
background: url('/images/banner.jpg') center center / cover no-repeat;
}
This is the point many designers run into when moving between raw CSS and the Divi Builder. In Divi, you can assign a background visually in seconds, but the module or section still depends on spacing settings to reveal that image properly.
The same CSS logic applies inside Divi
Divi wraps these properties in builder controls, but the underlying behavior does not change. If you understand what position, repeat, and size are doing in CSS, Divi's Background settings become predictable instead of trial and error.
In my experience, many teams focused on building effective online presences can style a section quickly, then lose time fixing unexpected cropping, awkward focal points, or empty containers. The fix usually is not another design trick. It is understanding the CSS rule behind the control. The same pattern shows up in layout work too, which is why references like these CSS Grid layout examples for modern section structure are useful. Strong backgrounds and strong layouts depend on the same habit of defining structure first, then styling with intent.
A quick property map
| CSS property | What it controls | Common use |
|---|---|---|
background-image |
Which image loads | Hero, banner, card, section |
background-repeat |
Whether the image tiles | Usually no-repeat |
background-position |
Where the image anchors | Often center center |
background-size |
How the image scales | Usually cover or contain |
Use a background image for decorative or layout-driven visuals. If the image carries meaning, such as product detail, text inside the graphic, or instructional content, it should not be treated as a purely decorative background.
Mastering Responsive Background Images
A hero can look right in Divi's desktop preview, then crop the subject's face on a phone. That usually happens because one background rule is doing too much work across very different screen shapes.
For a responsive background image of a div, the main decision is still cover versus contain. The difference is simple. One protects the container. The other protects the full image.

When cover works best
background-size: cover fills the entire container while preserving the image's aspect ratio.
.hero {
background: url('/images/hero-desktop.jpg') center center / cover no-repeat;
min-height: 70vh;
}
This is usually the right call for hero sections, full-width banners, and other areas where the background supports the layout more than the content. In Divi, this is the setting designers expect most of the time because it gives that full-bleed look without extra CSS.
The trade-off is cropping. The browser scales the image until no empty space remains, so part of the image will fall outside the visible frame if the aspect ratio does not match the container. That is fine for mood photography, gradients, textures, and abstract artwork. It is a poor fit for screenshots, packaging, diagrams, or any image where the edges carry meaning.
When contain is the safer choice
background-size: contain keeps the whole image visible and still respects its aspect ratio.
.feature-graphic {
background: url('/images/illustration-mobile.png') center center / contain no-repeat;
min-height: 320px;
}
I use this more carefully in Divi because it solves one problem while introducing another. The full graphic stays intact, but the container may show empty space above, below, or beside the image. That can work well for logos, badges, product cutouts, or promo graphics that need precise framing.
A practical rule helps here. Use cover when the section shape matters more than the full image. Use contain when the image content matters more than filling every pixel of the section.
A simple decision table
| Situation | Better choice | Why |
|---|---|---|
| Full-width hero background | cover |
Fills the section edge to edge |
| Decorative texture or pattern | cover |
Cropping usually does not matter |
| Logo, badge, or diagram used as background | contain |
Keeps the full image visible |
| Mobile promo panel with important framing | contain |
Prevents aggressive cropping |
Adjust the background by breakpoint
Responsive background work gets easier once you stop treating desktop and mobile as the same composition. In production, I often swap the asset, reposition the focal point, and change the scaling rule at the breakpoint instead of forcing one file to behave everywhere.
.hero {
background: url('/images/hero-desktop.jpg') center center / cover no-repeat;
min-height: 600px;
}
@media (max-width: 767px) {
.hero {
background-image: url('/images/hero-mobile.jpg');
background-position: center top;
background-size: contain;
min-height: 380px;
}
}
That pattern maps well to Divi's responsive controls. You can set different background positions per device in the Builder, but if the mobile crop needs different framing, a separate mobile asset usually gives a cleaner result than endless tweaking. For a wider look at breakpoint strategy and layout behavior, this guide to responsive web design with CSS is a strong reference.
Use image-set() for sharper delivery on high-density screens
Background images do not get the same built-in responsive treatment as an <img> with srcset, so CSS needs a little more intention. image-set() lets the browser choose the right asset for screen density.
.hero {
background-image: image-set(
url('/images/hero.webp') 1x,
url('/images/hero@2x.webp') 2x
);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
This works well for decorative backgrounds where you want sharper rendering on retina displays without sending the 2x file to every device. It does not fix poor composition, but it does improve delivery. In Divi builds, that matters most on large hero sections, call-to-action bands, and area-based layouts where the background carries a lot of the visual weight.
Overlays Accessibility and Readability
A hero section goes wrong fast when the photo looks great in the builder but the headline disappears once the page is live. The image is not usually the problem. The layer between the image and the text is.
Start with the semantic choice, because no overlay can fix the wrong HTML. Use a CSS background when the image is decorative and supports the layout. Use an <img> element when the image carries meaning, such as a product photo, portrait, chart, or step-by-step visual. If you would normally write alt text for it, it should not live in background-image.
That matters in Divi too. It is easy to add a background to a section, row, column, or module, but convenience should not decide semantics. Builder controls make background images easy to apply. They do not turn a content image into a decorative one.
For design treatments that combine visual layering and soft darkening, these CSS overlay image techniques are a useful reference.
Add an overlay for readable text
The cleanest overlay pattern is still a pseudo-element:
.hero {
position: relative;
background: url('/images/hero.jpg') center center / cover no-repeat;
color: #fff;
}
.hero::before {
content: "";
position: absolute;
inset: 0;
background: rgba(0, 0, 0, 0.45);
}
.hero-content {
position: relative;
z-index: 1;
}
I use this approach when I want independent control over the image and the darkening layer. It is easier to adjust opacity, swap the overlay color for brand styling, or animate the overlay on hover without rebuilding the whole background declaration.
A gradient overlay inside the background shorthand also works:
.hero {
background:
linear-gradient(rgba(0,0,0,0.45), rgba(0,0,0,0.45)),
url('/images/hero.jpg') center center / cover no-repeat;
}
Use that version when the overlay is simple and unlikely to change. In Divi builds, this distinction matters. A pseudo-element gives you more room for custom CSS and advanced effects. A gradient layer is faster to manage when the design is static.
Choose the right method for the job
| If the image is… | Use | Reason |
|---|---|---|
| A texture, abstract scene, or mood photo | CSS background | Decorative only |
| A product image | <img> |
Needs alt text |
| A team photo | <img> |
People are part of the content |
| A subtle brand pattern behind text | CSS background | Supports layout, not meaning |
Readability should win every time. If the text only works on one part of the image, the design is fragile.
In practice, that usually means softening the image, darkening it slightly, or limiting busy detail behind the copy. If you are still refining the asset itself before it becomes a background, this optimize images for web guide is a useful companion resource.
Performance Tuning for Background Images
A Divi page can look clean in the builder and still ship far too much image weight. Backgrounds are a common reason. They sit behind sections, rows, modules, and popups, so they are easy to miss during review, but the browser still has to download them.

Start with the file, not the script
The fastest background image is usually the one you resized, compressed, and exported properly before it ever reached Divi.
Use modern formats where browser support fits your audience. In practice, WebP is the safe default for most projects, and AVIF can reduce file size further when you can accept a more careful testing pass. Match the image dimensions to the actual container size, too. A 2400px-wide asset for a small promo card wastes bytes on every visit.
Background images also need more planning than <img> elements because they do not get automatic srcset behavior. If you need different files for desktop and mobile, handle that with image-set(), media queries, or Divi's device-specific background controls.
If you want a practical checklist for asset prep before you even get into CSS, this optimize images for web guide is a solid companion resource.
CSS backgrounds have a loading problem
Browsers handle content images better than decorative backgrounds. An <img> can use native lazy loading. A CSS background cannot.
That means off-screen backgrounds often download earlier than they should unless you intervene. For below-the-fold sections, that can inflate initial page weight and delay more important requests. Core Web Vitals breaks down this problem well in its analysis of why background images can hurt performance.
The practical rule is simple. Load the hero early. Delay decorative backgrounds that sit lower on the page.
A pattern that holds up in production
For custom builds, I prefer separating layout styling from the class that applies the image itself. That keeps the container stable while JavaScript adds the background only when the element is near the viewport. Conroy's lazy loading write-up shows this pattern clearly, and it maps well to Divi sites that need extra control beyond the builder UI.
.promo-panel {
min-height: 420px;
background-color: #e9e9e9;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.promo-panel-bg {
background-image: url('/images/promo-panel.webp');
}
Then apply the image class only when the div is near the viewport:
document.addEventListener("DOMContentLoaded", () => {
const targets = document.querySelectorAll(".lazy-bg");
const observer = new IntersectionObserver((entries, obs) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("promo-panel-bg");
obs.unobserve(entry.target);
}
});
}, {
root: null,
rootMargin: "200px 0px",
threshold: 0
});
targets.forEach((target) => observer.observe(target));
});
And your HTML stays simple:
<div class="promo-panel lazy-bg">
<div class="content">Content here</div>
</div>
This approach has a real trade-off. It adds JavaScript and a bit more setup, so I would not use it for every background on a small brochure site. I use it when a page has several large decorative sections, image-heavy promo blocks, or Divi layouts that already struggle with request weight.
Mistakes that cost the most
These are the problems I see most often on Divi builds:
- Large backgrounds assigned everywhere by default. Decorative sections, blurbs, and popups all pull full-size assets whether they add value or not.
- No distinction between hero images and lower-page assets. The first screen deserves priority. The seventh section does not.
- Desktop files reused on mobile. A cropped mobile-specific background is often dramatically lighter and usually looks better.
- No network check after design handoff. Divi makes background setup easy, but easy setup still needs verification in DevTools.
If a page feels heavier than it should, I check background images early. On visual builder projects, they are often the quiet source of bloated requests, especially when the design relies on multiple full-width sections with decorative photography.
Implementing Background Images in Divi
Divi makes the background image of a div feel visual, but it's still just CSS underneath. When you open a Section, Row, or Module and go to the Background tab, you're controlling the same concepts: image source, position, repeat, blend, and scale.
This is what that looks like in a real Divi interface:

Where to add the background in Divi
The most common targets are:
- Section background for full-width hero areas and broad content bands.
- Row background when you want the image constrained to a content width.
- Module background for blurbs, callouts, pricing boxes, and CTA blocks.
That choice matters. A Section-level background usually stretches across the layout. A Row-level background feels more contained. A Module background is best when the visual belongs to one component, not the whole area.
Match Divi controls to CSS concepts
Divi's visual labels map closely to CSS:
| Divi setting | CSS idea |
|---|---|
| Background Image | background-image |
| Background Image Position | background-position |
| Background Image Size Cover | background-size: cover |
| Background Image Size Fit | Similar to background-size: contain |
| Background Repeat | background-repeat |
If your image is clipping in a hero section, check Background Image Position before changing the image file. In Divi, shifting the focal point often fixes the layout faster than uploading a replacement.
Here's a walkthrough video if you want to see the builder behavior in action:
Use Divi's extras carefully
Divi also gives you gradients, blend modes, and parallax. They're useful, but they can get heavy fast if you stack too many visual effects on large backgrounds.
A few practical defaults work well:
- Use gradients to improve text contrast without editing the image file.
- Use blend modes for brand-color treatments on decorative sections.
- Use parallax sparingly. It can look polished, but it isn't always the best trade for mobile performance and readability.
When Divi backgrounds behave unpredictably, the fix usually isn't hidden deep in the builder. It's the same CSS logic you'd use outside Divi: size, position, repeat, and container dimensions.
Advanced Backgrounds with Divi Areas Pro
Static page sections are only one use case. The same background techniques become more interesting when the container is a popup, fly-in, mega menu panel, or injected WooCommerce message.
That's where advanced Divi workflows stop being about decoration and start being about context.

Popups need tighter background discipline
A popup background image isn't a full hero. It lives in a smaller, more constrained box. That changes what works.
For popups, I usually avoid wide cinematic images unless they're heavily cropped on purpose. Smaller containers tend to work better with:
- Soft textures behind a strong headline
- Brand gradients layered over a subtle image
- Pattern backgrounds that won't suffer if the popup dimensions change
- Focused compositions where the subject sits near the center
If the popup includes an offer, product detail, or form, the background should support the message, not compete with it.
A popup background should create atmosphere first and visual drama second.
Mega menus and injected content need consistency
Mega menus are another strong use case. A background image can define a menu panel without requiring extra image modules inside each column. That keeps the layout cleaner and gives you more room for links, icons, and CTA blocks.
The same idea applies to injected content areas. If you insert a promotional strip into selected templates, a background image can make it feel native to the design system rather than bolted on later.
The best setups usually follow three rules:
- Keep decorative backgrounds decorative. Don't hide important content in the image itself.
- Use the same position logic across breakpoints. If the focal point changes, define that deliberately.
- Treat overlays as part of the component. Don't rely on the image alone to carry contrast.
Apply the earlier CSS decisions inside dynamic containers
The principles don't change just because the element is triggered dynamically:
| Use case | Best background approach |
|---|---|
| Exit-intent popup | Centered image with overlay and short copy |
| Fly-in notice | Pattern or gradient, not a complex photo |
| Mega menu panel | Decorative branded texture with strong contrast |
| WooCommerce promo area | Simple background with readable CTA |
Builder users benefit most from understanding the CSS underneath. Once you know why cover, contain, overlays, and deferred loading matter, you can apply those choices to any Divi-built container, not just page sections.
A polished background image of a div isn't really about the div. It's about choosing the right visual role for that container, then making sure the image behaves correctly across design, accessibility, and performance.
If you want to build popups, fly-ins, mega menus, and injected content with the same level of control you use on the rest of your Divi site, Divimode is worth exploring. It gives Divi users practical tools for advanced on-page experiences while staying inside a familiar builder workflow.