ScanSkill
CSS Examples

How to Set a Fixed Background Image using CSS

In this example, we will learn how to set a fixed background image using CSS that will remain at its position even after scrolling. We will be using the background-attachment property to set the image fixed at its position in the background.

Prerequisites

Example

	body {
            background-image: url("<https://scanskill.com/wp-content/uploads/2022/02/cropped-Screen-Shot-2022-02-15-at-                                                                             13.25.57-1.png>");
            background-position: center;
            background-repeat: no-repeat;
            background-attachment: fixed;
        }

Output

Conclusion

In this example, we learned how to set a fixed background image using CSS. The background-attachment: fixed value sets the background image fixed at its position even after scrolling.