Background Attachment Property

Last updated: 2026-09-13

background-attachment Background Attachment Property

background-attachment decides whether a background image scrolls with the page. The default scroll means the background scrolls with the element's content; fixed pins the background to the viewport, producing a parallax effect; local makes the background scroll with the element's internal content. It is often used for visual effects.

Category
Initial Valuescroll
InheritedNo
Applies To
Animation Type
CSS VersionCSS1
StatusStandard

📝 Syntax

background-attachment: scroll | fixed | local;

⚙️ Values

ValueTypeDescription
scroll | fixed | localKeywordBackground scrolling behavior

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
background-attachment v1 v12 v1 v1 v1
Supported in all major browsers
Tip: The fixed value pins the background to the viewport, commonly used to create parallax scrolling effects.
Warning: background-attachment: fixed performs poorly on mobile, and some mobile browsers ignore the value entirely.

❓ FAQ

QWhat is the difference between scroll, fixed, and local in background-attachment?
AThey differ in what the background is positioned relative to. scroll (the default): the background is positioned relative to the element and scrolls with it. fixed: the background is pinned to the viewport and stays still while the page scrolls, creating a parallax effect. local: the background is positioned relative to the element's inner content, so it scrolls when the element's internal content scrolls, e.g. in an overflow: auto container.
QHow do I create a parallax scrolling effect?
ASet background-attachment: fixed, and since the background is pinned to the viewport, the foreground content moves while the background stays still — that is the parallax feel. The classic approach is giving several sections different background images with fixed so backgrounds swap as you scroll. Note that iOS and some mobile browsers ignore fixed, so you may need a separate treatment.
QWhy doesn't background-attachment: fixed work on mobile?
AMainly for performance. Mobile browsers like iOS Safari degrade fixed backgrounds to scroll to save memory and keep scrolling smooth, so the background scrolls with the content. Workarounds: use an ordinary full-bleed background on mobile, or a JS parallax library (such as Rellax) built on transform, and enable fixed only on desktop.
QWhen should I use the local value?
Alocal suits containers with their own scrollbar, such as overflow: auto chat windows, code blocks, or data lists. With background-attachment: local the background scrolls along with the inner content instead of staying glued to the container, which visually mimics a 'paper texture that belongs to the content'.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏