A complete image data URL can be present in the stylesheet while an empty element shows no picture. Before replacing the encoded string, inspect the element’s box: a background image does not give an otherwise empty block the image’s height.
This example uses the Image to Base64 Converter to prepare a decorative background, then gives its empty container visible dimensions.
Check the generated rule and its matching element
Choose a small decorative image in the converter, confirm its preview and use Copy CSS rule. The current tool generates a .my-element rule containing the complete background URL, background-repeat: no-repeat and background-size: cover. It does not set the element’s width or height.
Apply that class to the intended empty block:
<div class="my-element"></div>
Keep the generated data URL intact. If you rename the class, update both the selector and the HTML. Our image data URL guide explains the complete prefix and common copying errors.
Give the empty block a height
Inspect the element in browser developer tools. Check its rendered width and height separately from the background-image value. If the rule matches but the block has zero height, changing Base64 characters will not create a visible area.
Add this sizing rule after the generated CSS for the example container:
.my-element {
width: 120px;
aspect-ratio: 3 / 2;
background-position: center;
}
With an automatic height, the 3:2 ratio gives this 120-pixel-wide block an 80-pixel height. MDN’s aspect-ratio reference explains how a preferred box ratio participates in automatic sizing. If another rule fixes both width and height, changing the ratio alone will not override those dimensions.
Choose dimensions appropriate to your layout. This CSS changes the container and how the background is painted; it does not edit the encoded image file.
Separate visibility from background fitting
We tested the current converter code locally in Chrome with a 60 by 40 pixel decorative PNG containing colored quadrants and black side stripes. Its generated data URL decoded back to the original file bytes. We applied the exact generated CSS, then inspected box measurements and the rendered screenshot.
| Empty block setup | Measured box | Observed result |
|---|---|---|
| Width only, generated background rule | 120 by 0 | No visible image area |
| Width plus 3:2 aspect ratio | 120 by 80 | Whole graphic visible |
| Square with centered cover | 120 by 120 | Side stripes cropped |
| Square with centered contain | 120 by 120 | Whole graphic with gaps above and below |
The square comparisons were separate layout choices after fixing the height. The generated cover setting fills the box while keeping the image ratio, so mismatched proportions can crop an edge. To retain the whole graphic, use background-size: contain and keep no-repeat; uncovered space shows the background color. MDN documents these background-size choices.
These observations describe one fixed-size fixture. Inspect your actual background at each layout size, especially when its important visual details sit near an edge.
Keep meaningful images out of this decorative shortcut
Use this empty-background approach for decoration that adds no necessary information. W3C’s decorative-image guidance recommends CSS backgrounds where appropriate for that role. A product diagram, instruction image or image-only link needs its meaning or function available to the reader.
If the image conveys information, use an appropriate image element and alternative text instead; the alt-text guide explains that choice. After saving your layout, confirm the intended element has a visible box, the right background and suitable cropping on the real page.