{"id":196157,"date":"2015-02-17T15:08:58","date_gmt":"2015-02-17T22:08:58","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=196157"},"modified":"2017-06-06T16:39:47","modified_gmt":"2017-06-06T23:39:47","slug":"background-attachment","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/b\/background-attachment\/","title":{"rendered":"background-attachment"},"content":{"rendered":"

The background-attachment<\/code> property in CSS specifies how to move the background relative to the viewport.<\/p>\n

There are three values: scroll<\/code>, fixed<\/code>, and local<\/code>. The best way to explain this is via demo (try scrolling the individual backgrounds):<\/p>\n

See the Pen Background attachment demo<\/a> by Timothy Miller (@tjacobdesign<\/a>) on CodePen<\/a>.<\/p>\n

There are two different views to think about when talking about background-attachment<\/code>: the main view (browser window), and the local view (you can see this in the demo above).<\/p>\n

scroll<\/code> is the default value. It scrolls with the main view, but stays fixed inside the local view.<\/p>\n

fixed<\/code> stays fixed no matter what. It’s kind of like a physical window: moving around the window changes your perspective, but it doesn’t change where things are outside of the window.<\/p>\n

local<\/code> was invented because the default scroll<\/code> value acts like a fixed background. It scrolls both with the main view and<\/em> the local view. There are some pretty cool things<\/a> you can do with it.<\/p>\n

Related<\/h3>\n