Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallUse background-attachment: fixed on the element that owns the background. That anchors the image to the viewport instead of moving it with the page; combine it with an explicit fallback color, size, position and repeat rule for a dependable result.
The minimal CSS
Apply the image and attachment behavior to the element that should display it:
body {
background-image: url('background.jpg');
background-attachment: fixed;
}
The image path must point to an asset your site is authorized to use. On a page that has enough content to scroll, the background remains anchored to the viewport while the document moves over it.
A practical full-viewport example
For a readable, full-page presentation, define every related property rather than relying on browser defaults:
#1 Best Overall
html,
body {
min-height: 100%;
}
body {
margin: 0;
background-color: #222;
background-image: url('background.jpg');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
color: #fff;
}
.content {
max-width: 70rem;
margin: 0 auto;
padding: 6rem 1.5rem;
}
background-color is the fallback shown while the image is loading or if it cannot be loaded. The dark color in this example also provides a base behind light text, but you still need to check contrast against the actual image crop.
What each declaration controls
| Property | Example | Effect |
|---|---|---|
background-attachment |
fixed |
Anchors the background to the viewport. |
background-size |
cover |
Fills the box while preserving aspect ratio; edges can be cropped. |
background-position |
center |
Chooses which part of the image stays visible when cropping occurs. |
background-repeat |
no-repeat |
Prevents the image from tiling. |
background-color |
#222 |
Provides a visible fallback and a base for text contrast. |
Understand the attachment values
The property has three useful values. fixed positions the background relative to the viewport. It does not move with page scrolling, and on an element that has its own scrolling mechanism it still does not move with that element’s contents. When fixed is set, background-origin is ignored.
| Value | Attachment relationship | Use it when |
|---|---|---|
fixed |
The image is tied to the viewport. | You want content to move across a stationary visual. |
scroll |
The image is attached to the element and moves as that element moves with the page. It does not scroll with the element’s own contents. | You want ordinary document-background behavior. This is the initial value. |
local |
The image moves with the element’s contents when the element itself scrolls. | You are styling a scrollable panel and want its background to follow the panel content. |
The distinction is visible only when there is content to scroll. A short box or a page that fits entirely in the viewport may make fixed and scroll appear identical.
Choose the image framing
Use cover to fill the viewport
background-size: cover scales the image until the entire box is filled, preserving its aspect ratio. Because the image and viewport rarely have the same proportions, some edges may be outside the box. Move the focal point with background-position:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →body {
background-position: 50% 30%;
background-size: cover;
}
The first percentage controls the horizontal position and the second controls the vertical position. A value such as center top keeps a subject near the top edge; right center favors the right side.
Use contain when the complete image matters
background-size: contain scales the image so that it is entirely visible inside the box. It preserves the aspect ratio but can leave empty bands when the box and image have different shapes. Keep a matching background-color so those bands look intentional:
.poster {
min-height: 32rem;
background-color: #111;
background-image: url('poster.jpg');
background-position: center;
background-repeat: no-repeat;
background-size: contain;
background-attachment: fixed;
}
Prevent accidental tiling
If the image is smaller than its box and you omit background-repeat, the default tiling behavior can produce a pattern rather than a single photograph. Set no-repeat for a single image, or deliberately choose repeat-x, repeat-y or repeat for a texture.
Apply the effect to a section or component
The property belongs on the element whose background you want to paint; it does not have to be body:
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →.hero {
min-height: 75vh;
padding: 8rem 2rem;
background-color: #263238;
background-image: url('hero.jpg');
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.hero__content {
max-width: 42rem;
}
The element needs enough height for the framing and a page needs scrollable content for the fixed-versus-moving relationship to be apparent. If a parent creates a separate scrolling region, test that region specifically: fixed remains viewport-relative, while local is the value that follows an element’s own contents.
Keep foreground text readable and resilient
Do not put essential information only in the image
A CSS background is presentation. Browsers do not expose background-image as an alternative text equivalent for assistive technology. Put headings, instructions, labels and other required information in real HTML, and use the background only to support that content.
Rank #3
Check contrast across every crop
A centered desktop crop may place text over a dark area while a narrow portrait crop puts the same text over a bright subject. Check the largest and smallest intended widths, both orientations and any alternate focal positions. If necessary, add a solid or translucent overlay:
.hero {
position: relative;
isolation: isolate;
background-color: #222;
background-image: url('hero.jpg');
background-attachment: fixed;
background-position: center;
background-size: cover;
}
.hero::before {
content: '';
position: absolute;
inset: 0;
background: rgb(0 0 0 / 35%);
z-index: -1;
}
.hero__content {
position: relative;
}
The color fallback remains useful even with an overlay: it preserves legibility before the image arrives and when a request fails.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Mobile browsers need device-specific testing
Broad browser support does not guarantee identical scrolling or repaint behavior on every phone. A Can I Use compatibility snapshot reports 97.26% global usage support for the fixed value; its usage-share context is attributed to StatCounter GlobalStats for August 2026. The same compatibility material identifies partial support in iOS Safari versions shown on that page, and notes that some mobile devices can delay updating the background position after scrolling.
Treat those figures as dated compatibility data, not as a promise for a particular handset. Test the mobile browsers, operating-system versions and orientations that matter to your audience. If the effect is decorative and not important on narrow screens, let the image scroll normally there:
@media (max-width: 48rem) {
body {
background-attachment: scroll;
}
}
This is a graceful design choice, not a claim that the property is categorically unsupported on mobile. You can also change the image position or use a separate mobile asset if the subject is cropped out at narrow widths.
Rank #4
- B5 Recipe Book: This hardcover blank recipe book measures 10''×7.3'', containing 150 blank pages, comes with 1 sheet of DIY category stickers, perfect for writing down your own recipes and organizing them in one place.
- Practical Layout - 5 pages of conversion charts show you everything you'll ever need to know in the kitchen. The table of contents will help organize your personal favorite recipes. A back pocket is designed for loose items.
- Easy to Use - This blank cookbook is made of high-quality paper with a beautiful hardcover for long-term use. The sturdy gold double-wire spiral binding makes writing easier and page turning smoother.
- Make Your Own Recipes - This blank cookbook has up to 150 blank pages for you to write in your own recipes, with plenty of space to record ingredients and instructions. You can write down all the special tips for your family members.
- Thoughtful Gift - A personalized recipe book makes a thoughtful gift for your children or newlyweds, and a great gift for housewarming, weddings, bridal showers, anniversaries, or any other occasion.
Responsive patterns that hold up
Keep a subject visible
body {
background-position: 65% center;
}
@media (max-width: 48rem) {
body {
background-position: 72% center;
}
}
The mobile rule can move the focal point without changing the attachment behavior.
Recommended Free Tools
Use a deliberate section height
For a hero, use a minimum height such as min-height: 75vh rather than forcing a fixed height that can clip text when the font size or language changes. Let the content determine the final height when it needs more room.
Separate decorative and semantic images
If the picture itself conveys information, place it in an <img> with meaningful alternative text instead of relying on a background. Use the fixed background for atmosphere, texture or visual context behind semantic HTML.
Troubleshoot common failures
The image moves with the page
- Confirm the declaration is exactly
background-attachment: fixedand is applied to the element that owns the background. - Check the browser’s computed styles for a later rule that changes the value to
scroll. - Make sure there is enough page content to scroll; without scrolling, the difference cannot be seen.
- If the behavior is wrong only on a phone, compare it with the mobile media query and test the actual browser version.
The background is cropped in the wrong place
coverintentionally crops one dimension. Adjustbackground-positiontoward the subject.- Use
containwhen showing the complete image is more important than filling the box, and provide a suitable fallback color for the remaining space. - Check portrait and landscape orientations separately; the visible crop changes with the viewport ratio.
The image repeats
Add background-repeat: no-repeat. If you are using the background shorthand elsewhere, ensure that a later shorthand is not resetting the longhand values.
Text becomes unreadable
Set a fallback color, inspect the image behind every text block at responsive widths, and add an overlay or reposition the image when contrast changes across the crop. Never depend on the picture alone to communicate required information.
Best Value
A scrollable panel behaves unexpectedly
Remember that fixed is viewport-relative. If the background should travel with the panel’s own contents, use background-attachment: local on that scrollable element and verify the result in the target browsers.
The image appears blank
- Verify the URL, filename capitalization and server response.
- Check that the stylesheet is loaded and that the element has visible dimensions.
- Look for a network or content-security-policy error in the browser developer tools.
- Keep the fallback color so a failed image request does not leave text over an undefined background.
Performance and reliability considerations
- Choose an image dimension appropriate for the largest display size and compress it before publishing. An unnecessarily large background increases transfer and decoding work.
- Prefer modern formats your supported browsers handle, while retaining the fallback color for failures.
- A fixed image that covers a long page can remain visible for the entire session; test scrolling on lower-powered phones rather than assuming desktop behavior carries over.
- Keep the focal point and contrast rules in your responsive CSS so a future image replacement does not silently hide a subject or reduce legibility.
- Use browser developer tools to inspect computed styles, network responses and the actual painted crop at each breakpoint.
A repeatable testing checklist
- Load the page with the image request blocked and confirm the fallback color still makes the text readable.
- Scroll a long page on desktop and verify that the background stays viewport-relative while content moves.
- Resize through your breakpoints and inspect the focal point, crop and text contrast.
- Test the mobile browsers and orientations that your audience uses, including the narrow-screen rule if you added one.
- Open any independently scrolling panel and confirm whether it needs
fixed,scrollorlocal. - Run keyboard and assistive-technology checks to ensure all essential information is present in HTML, not only in the image.
Or skip the browser setup
If you need rendered screenshots to check how the CSS looks at different viewport sizes, ScreenshotNeo can capture a URL through one request. Its cleaner capture flow accepts consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets before the shot; bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and each response identifies the page verdict and billing status in headers. An MCP server lets Claude, Cursor and other MCP clients call take_screenshot, get_page_info and capture_pdf.
See the ScreenshotNeo API documentation for all options, including viewport and device presets, full-page capture, custom CSS and JavaScript, waits, headers, cookies, geolocation, dark mode and PDF output.
cURL
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python
import requests; r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90); open("shot.webp", "wb").write(r.content)
Node.js
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' }); const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
The Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 shots, and every feature is available on every plan. Create a free ScreenshotNeo account.
Frequently Asked Questions
Is background-attachment: fixed the same as position: fixed?
No. background-attachment controls how a background image is painted; position: fixed places an actual HTML element relative to the viewport. They solve different layout problems and can be used independently.
Why did my fixed background stop working after I added a background shorthand?
The shorthand resets background sub-properties that you omit. Put background-attachment: fixed after the shorthand, or use explicit longhand declarations so the intended value remains clear.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

