Set background image as fixed with CSS


Use the background-attachment property to display the background image as fixed.

Example

You can try to run the following code to implement the background-attachment property −

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         body {
            background-image: url("https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg");
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-position: right top;
         }
      </style>
   </head>
   <body>
      <h1>Background Image</h1>
   </body>
</html>

Updated on: 01-Jul-2020

618 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements