how to make background image fixed when scrolling code example

Example 1: how to make fixed background image in css

body {
  background-image: url("img_tree.gif");
  background-repeat: no-repeat;
  background-attachment: fixed;
}

Example 2: html static background

body {
  background-image: url("img_tree.gif");
  
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  
  background-size: cover;
}

Example 3: How to make background fixed while scrolling

On-scroll fixed background

Tags:

Css Example