HTML Background

HTML Background:

A background image can be specified for all webpages these days.

To add background image for any website we can use two ways either use HTML style attribute

Or CSS background-image property.

Example:

<p style = “background-image”: url(‘smiley_pic.jpg’);>

If you want add background image for entire webpage then follow below example:

<style>

<body>{

Background-image: url(‘smily_pic.jpg’);

}

</style>

Note:

If background image repeating automatically then you can use background-repeat property  to no-repeat.

Example:

<style>

<body>{

Background-image: url(‘smily_pic.jpg’);

Background-repeat: no-repat;

}

</style>

Background Cover:

If you want to cover the background image to the entire element then you can use the background-size property to cover and also make sure the entire element is always covered then set the background –attachment property fixed.

Example:

<style>

<body>{

Background-image: url(‘smily_pic.jpg’);

Background-repeat: no-repat;

Background-size:cover;

Background-attachment:fixed;

}

</style>

Join Our Newsletter