How to Make a Fixed Background Image Using CSS

This is just a simple bit of CSS but I thought I would probably need it again in the future. Adding a fixed background image to a website is something I do very rarely but every now and then there is cause for it. The code I have shown below demonstrates how to add a fixed background image to the body tag of a website using CSS but you can also use the same strategy to add a fixed background image to a DIV or other element using CSS.

Check it out:

<style type="text/css">
    body {
        background-image: url(image.jpg);
        background-repeat: no-repeat;
        background-position: top left;
        background-attachment: fixed;
     }
</style>

No related posts.

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

Thanks Man for this its what I need for my site

@createweb Glad to hear it was helpful.

Thanks man that was helpfull

Leave a comment

(required)

(required)