How to add a Background Image that scales with the Browser Window |Using CSS


To make the background image scale with the browser window we need to use the Background size property with value of cover like so,

CSS Code:

<style>
     html{
       background-image: url(my_background.jpg);
       background-repeat: no-repeat;
       background-position: center center;
       background-attachment: fixed;
       -webkit-background-size: cover;
       -moz-background-size: cover;
       -o-background-size: cover;
       background-size: cover;
       color: #fff;
       background-color: #000;
        }
<style>

Comments

Check out

CSS Sprites | What are They?

Login form | Using CSS3

Remove Scrollbars from syntaxhighlighter

Adding a button in HTML | styling a button

HTML5 Semantic Tags | What do they mean

How to remove plus and minus characters from input type number

HTML5 | LocalStorage

How CSS3 Works

jQuery Resources | Support and tutorial help