
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
Background Attachment in CSS
The background-attachment property in CSS is used to specify the position of background image when the page is scrolled with respect to the viewport. It can have the values scroll, fixed and local.
Syntax
The syntax of CSS background-attachment property is as follows −
Selector { background-attachment: /*value*/ }
Example
The following examples illustrate CSS background-attachment property −
<!DOCTYPE html> <html> <head> <style> body { background-repeat: no-repeat; background-attachment: local; background-position: center; background-image: url("https://www.tutorialspoint.com/power_bi/images/power-bi-mini-logo.jpg"); } div { padding: 40px; margin: 30px; } .in { background: rgba(0,0,0,0.4); } </style> </head> <body> <div id="one"> <div class="in"></div> <div class="in"></div> <div class="in"></div> <div class="in"></div> <div class="in"></div> </div> </body> </html>
Output
This gives the following output −
On scrolling, we get the following output −
Example
<!DOCTYPE html> <html> <head> <style> body { background-repeat: no-repeat; background-attachment: fixed; background-position: 10% 5%; background-image: url("https://www.tutorialspoint.com/power_bi/images/power-bi-mini-logo.jpg"); } div { padding: 80px; margin: 30px; border-radius: 4%; } .in { background: rgba(0,40,0,0.4); } </style> </head> <body> <div id="one"> <div class="in"></div> <div class="in"></div> <div class="in"></div> <div class="in"></div> <div class="in"></div> </div> </body> </html>
Output
This gives the following output −
On scrolling, we get the following output −
- Related Articles
- Usage of background-attachment property in CSS
- Set the Background Attachment with CSS
- Background Repeat in CSS
- CSS background property
- CSS Background Properties
- Setting Background Position in CSS
- Animated background with CSS
- CSS Multi background property
- CSS background-size property
- CSS background-origin property
- CSS background-clip property
- CSS background-image property
- Background Repeat Using CSS
- Usage of background property in CSS
- The Background Shorthand Property in CSS

Advertisements