CSS Background – What is Background in css

The CSS background properties are used to define the background effects for elements.
CSS background properties are as follows:-

background-color

background-image

background-repeat

background-attachment

background-position

Background Image:-

The background-image property specifies an image to use as the background of an element.

By default, the image is repeated so it covers the entire element.

The background image for a page can be set like this:-

body { background-image: url(“image url”);}

Note: When using a background image, use an image that does not disturb the text.

Repeat Horizontally-

By default, the background-image property repeats an image both horizontally and vertically.

Some images should be repeated only horizontally or vertically, or they will look strange, like thisbody { background-image: url(“gradient_bg.png”);}If the image above is repeated only horizontally (background-repeat: repeat-x;), the background will look better:body { background-image: url(“cssimage.png”); background-repeat: repeat-x;}

Repeat Vertically-

Set position and no-repeat

Showing the background image only once is also specified by the backgroun-repeat property:body { background-image: url(“iimage.png”); background-repeat: no-repeat;}In the example above, the background image is shown in the same place as the text. We want to change the position of the image, to change the image position we use background-position property.body { background-image: url(“img_tree.png”); background-repeat: no-repeat; background-position: right top;}

Background Color:-

The background-color property specifies the background color of an element.

The background color of a page is set like this:-

body { background-color: green;}

in CSS, a color is specified by:

a valid color name – like ‘green’

a HEX value – like ‘#oosjo’

an RGB value – like ‘rgb(879,88,0)’

In the example below, the <h1>, <p>, and <div> elements have different background colors: