Inspect CSS Background Size in Safari Web Inspector
In this article
Yes, you can inspect and debug background-size in Safari’s Web Inspector, just as you would any other CSS property. Open the Inspector (right-click → Inspect Element, or press Option+Command+I), select the element with the background, and look in the Styles panel on the right—there you’ll see the computed value and the source rule. You can even toggle the property on/off or edit it live to test different values.
Where to Find Background-Size in the Inspector
In Safari’s Web Inspector, the Styles sidebar shows all CSS rules applied to the selected element, including those from stylesheets, inline styles, and user agent styles. Scroll through the list to find background-size; if it’s not visible, it may be inherited or not set. To see the final computed value (e.g., after shorthand expansion), switch to the “Computed” tab (sometimes labeled “Computed Style”) and search for “background-size.” There you’ll see the resolved value in pixels or keywords.
How Background-Size Works in CSS
The background-size property controls the size of a background image. It accepts:
- Length values like
100px 50px(width and height) or a single value (height auto). - Percentage values relative to the element’s background positioning area (usually the padding box).
- Keywords:
auto(natural size),cover(scale to cover the area, cropping overflow), andcontain(scale to fit entirely, leaving empty space). - Multiple values for multiple backgrounds, separated by commas.
When you use shorthand like background: url(...) no-repeat center/cover;, the cover is the background-size component. The Inspector will show the expanded longhand property.
Editing Background-Size Live
In the Styles panel, you can click on the value of background-size and type a new value. Press Enter to apply it immediately to the page. This is great for testing different sizes without reloading. You can also toggle the checkbox next to the property to disable it temporarily, which helps isolate issues. For example, if your background image is cropping unexpectedly, try switching between cover and contain to see which fits your design intent.
Common Problems and Misconceptions
One frequent issue is that background-size appears not to work when the background image is set via the background shorthand in an older Safari version—but that’s usually because the value is being overridden by a more specific rule. Check the “Cascade” section in the Inspector to see which rule wins. Another misconception: background-size: 100% 100% stretches the image to fill the element, which can distort it; use cover or contain to preserve aspect ratio. Also note that background-size does not affect the element’s own dimensions—it only scales the image inside the element.
Comparing Safari’s Inspector to Other Browsers
Safari’s Web Inspector is similar to Chrome DevTools and Firefox Developer Tools, but with some differences. In Chrome, you can hover over the value to see a visual preview; Safari lacks that. However, Safari’s “Computed” tab is very detailed, and the “Layer” view can show how backgrounds render. If you’re used to Chrome, you might find Safari’s layout slightly less intuitive, but the core functionality—editing, toggling, and inspecting—is identical. For responsive design, Safari’s Inspector has a “Responsive Design Mode” (under Develop menu) that lets you test different viewport sizes, which affects background-size if you use media queries.
Tips for Debugging Background-Size Issues
- Select the element with the background and confirm the image is actually loading (check the Network tab).
- In the Styles panel, look for any rule that sets
background-sizeand check its specificity. - Use the “Computed” tab to see the final value—if it shows
auto, your rule may be overridden. - Try editing the value directly to a known value like
coverto see if it changes. - If using multiple backgrounds, remember that each layer has its own size; the Inspector shows them as a comma-separated list.
Frequently Asked Questions
Why doesn’t background-size show up in the Styles panel?
It might be because the property isn’t set on that element—it could be inherited from a parent or not defined at all. Check the “Computed” tab; if it shows auto, that’s the default. Also, if you used the background shorthand, the longhand background-size appears only if it was included; otherwise it’s set to auto.
Can I change background-size for multiple elements at once?
Yes, but not directly in the Inspector. You can edit the CSS rule in the Styles panel, and that change applies to all elements that match the selector. For example, if you have a class .hero, editing the rule affects all elements with that class.
How do I see the actual pixel size of the background image?
In the “Computed” tab, the background-size value is shown in pixels if the image has a natural size and you’ve used auto or a length. For cover or contain, it shows the computed pixel dimensions after scaling. You can also hover over the element in the page and the Inspector highlights the element’s box, but not the background image’s size directly.
Does Safari support background-size in all versions?
Yes, background-size is supported in all modern Safari versions (5.1+ with prefix, 9+ unprefixed). If you’re targeting very old versions, you may need the -webkit- prefix, but that’s rarely necessary now.
Why does my background image appear stretched even with cover?
That shouldn’t happen with cover—it maintains aspect ratio. If it looks stretched, the image itself may have a distorted aspect ratio, or you might have set background-size: 100% 100% elsewhere. Check the computed value to confirm.
Can I inspect background-size on pseudo-elements like ::before?
Yes, select the pseudo-element in the Inspector by clicking on the “::before” or “::after” in the Elements panel. The Styles panel will show its rules, including background-size if set.