CSS Background Shorthand



CSS background - Shorthand property

To shorten the code, it is also possible to specify all the background properties in one single property. This is called a shorthand property.

You can use the shorthand property background:

Example

Specify that the background image should be fixed:/p>

    
    <!DOCTYPE html>
    <html>
    <head> 
    <style> 

    body {
    background:#ffffff url("img_tree.png") no-repeat right top;
    margin-right: no-repeat;
        }

    </style> 
    </head> 
    <body> 
      
    <h1>The background Property</h1>

    <p>The background property is a shorthand property for 
    specifying all the background properties in one declaration.</p>

    <p>Here, the background image is only shown once, and 
    it is also positioned in the top-right corner.</p>
    
    <p>We have also added a right margin, so that the text
    will not write over the background image.</p>
        

        </body>
        </html>
        
      

Result:
Example Image