The background-attachment property controls how a background image moves when the page or an element scrolls. It is especially useful for hero sections, parallax-style layouts, and scrollable panels.
01
Scroll Behavior
Control background movement.
02
Syntax
scroll, fixed, or local.
03
Fixed Hero
Viewport-locked backgrounds.
04
scroll Default
Normal page scrolling.
05
local Boxes
Inner overflow scrolling.
06
Background Shorthand
Part of background CSS.
Fundamentals
Definition and Usage
The background-attachment CSS property sets whether a background image scrolls with its element, stays fixed relative to the viewport, or scrolls with the element’s own overflow content.
This property is commonly used with background-image to create fixed hero banners, layered page designs, and scrollable note areas where the background should move with inner text.
💡
Beginner Tip
If you do nothing, backgrounds use scroll by default. Use fixed only when you intentionally want a viewport-locked background effect.
Foundation
📝 Syntax
Apply background-attachment to any element that has a background image or gradient:
The initial value of background-attachment is scroll. That means the background image moves with the element’s border box as the page scrolls, which is the normal behavior most layouts expect.
Reference
💎 Property Values
There are three keyword values for background-attachment.
Value
Example
Meaning
scroll
background-attachment: scroll;
The background scrolls with the element on the page
fixed
background-attachment: fixed;
The background stays fixed relative to the viewport
local
background-attachment: local;
The background scrolls with the element’s inner overflow content
scroll
The default behavior. The background moves normally with the element when the page scrolls.
Stripes move with the box when you scroll the page.
Best for standard sections and full-page backgrounds.
fixed
Keeps the background anchored to the viewport for hero and parallax-style effects.
Stripes stay pinned to the screen while the box moves.
Popular for landing-page hero banners.
local
The background scrolls with content inside a box that has its own scrollbar.
Scroll inside this box
Background moves with content
Useful for notes, chat windows, and inner panels.
See the Difference: scroll vs fixed
Scroll this page slowly. The left panel keeps its stripes aligned with the box. The right panel keeps stripes fixed to the viewport, so the pattern appears to slide inside the box.
↓ Scroll the page to compare both panels
scroll
fixed
scroll: background moves with the element. fixed: background stays locked to the browser window.
Scope
When to Use Each Value
scroll — Default page sections, cards, and normal background images.
fixed — Hero headers, full-width banners, and parallax-style visual effects.
local — Scrollable containers such as note panels, code blocks, or chat areas.
Compare
scroll vs fixed vs local
Value
Moves with
Best for
scroll
The element on the page
Standard layouts and section backgrounds
fixed
The viewport
Hero images and parallax-style designs
local
The element’s inner scrollable content
Overflow boxes and nested scroll areas
Preview
👀 Live Preview
Use the side-by-side panels above in the Property Values section, or try this full-width fixed hero while scrolling the page:
Fixed Background Hero
The gradient stays viewport-fixed while the rest of the page scrolls.
Compare this hero with the scroll vs fixed panels to see how attachment changes background motion.
Hands-On
Examples Gallery
Try background-attachment with all three values, a fixed hero, a local scroll box, and default scroll sections.
📚 Basic Values
Compare scroll, fixed, and local to understand how each one behaves.
Because scroll is the default, you often do not need to write it unless you are overriding another value.
🧠 How background-attachment Works
1
You add a background image
Set a photo, pattern, or gradient with background-image.
Background layer
2
You choose an attachment value
Pick scroll, fixed, or local.
Attachment rule
3
The browser decides what moves
The background either follows the page, stays in the viewport, or scrolls inside the element.
Scroll behavior
=
🖼️
Controlled background motion
You get the scroll effect you want without changing the image itself.
Compatibility
Universal Browser Support
background-attachment is widely supported, but fixed can behave differently on some mobile browsers.
✓ Baseline · Background properties
Reliable support in modern browsers
Chrome, Firefox, Safari, Edge, and Opera all support scroll, fixed, and local.
96%Modern browser support
Google Chrome1+ · Desktop & Mobile
Full support
Mozilla Firefox1+ · Desktop & Mobile
Full support
Apple Safari1+ · macOS & iOS
Full support
Microsoft Edge12+ · Modern versions
Full support
Opera3.5+ · Modern versions
Full support
Mobile caveat
Some mobile browsers treat background-attachment: fixed like scroll for performance reasons.
📱
iOS SafariFixed backgrounds may not behave as expected · Test on device
Partial
background-attachment property96% supported
Bottom line: Use background-attachment confidently, but test fixed layouts on mobile and provide a graceful fallback.
Wrap Up
Conclusion
The background-attachment property gives you control over how background images move during scrolling. Use scroll for normal layouts, fixed for hero and parallax-style designs, and local for inner scroll containers.
Understanding these three values helps you choose the right background behavior without extra JavaScript or complicated workarounds.
Pair fixed with background-size: cover on hero banners
Use local in overflow containers like notes and chat panels
Test fixed backgrounds on mobile devices
Keep text readable over background images
❌ Don’t
Assume fixed will look identical on every mobile browser
Use fixed everywhere without a performance reason
Forget that scroll is already the default
Expect local to matter without inner scrolling content
Rely on fixed backgrounds for essential readability alone
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about background-attachment
Use these points when choosing background scroll behavior.
5
Core concepts
🖼️01
Scroll Control
Sets background movement.
Purpose
📝02
Three Values
scroll, fixed, local.
Values
🏠03
Fixed Hero
Viewport-locked backgrounds.
Use case
⚡04
scroll Default
Normal page behavior.
Default
📱05
Test Mobile
Fixed may differ on iOS.
Caution
❓ Frequently Asked Questions
The background-attachment property controls whether a background image scrolls with the element, stays fixed in the viewport, or scrolls with the element's own overflow content.
The initial value is scroll, which means the background image moves with the element as the page scrolls.
scroll moves the background with the element. fixed keeps the background anchored to the viewport, which can create a parallax-style effect.
Use local when an element has its own scrollable content and you want the background to move with that inner content rather than staying fixed to the element box.
Support varies on mobile browsers, especially iOS Safari, where fixed backgrounds may behave like scroll. Always test on real devices and provide a fallback design.