CSS Basic Tutorial
CSS Flexbox
In CSS, the background
property is used to define the background styling of an element. It can be used to set a background color, image, position, and more. Here's a breakdown of how to use the background-related properties in CSS:
Background Format
|
Description
|
---|---|
Background Color
|
Sets the background color of an element.
|
Background Image
|
Sets an image as the background of an element.
|
Background Repeat
|
Controls if/how the background image is repeated.
|
Background Position
|
Sets the position of the background image.
|
Background Size
|
Specifies the size of the background image.
|
Background Attachment
|
Determines if the background image scrolls with the page or stays fixed.
|
Background Shorthand
|
You can combine multiple background properties into a shorthand property.
|
Sets the background color of an element.
background-color: color | transparent | initial | inherit;
Sets an image as the background of an element.
background-image: url('url') | none | initial | inherit;
Controls if/how the background image is repeated.
background-repeat: repeat | repeat-x | repeat-y | no-repeat | space | round | initial | inherit;
Try it yourself
Currently Active Property:
Sets the starting position of the background image.
background-position: value;
Try it yourself
Currently Active Property:
Specifies the size of the background image.
background-size: auto | length | cover | contain | initial | inherit;
Try it yourself
Currently Active Property:
Determines whether the background scrolls with the page or remains fixed.
background-attachment: scroll | fixed | local | initial | inherit;
Try it yourself
Try it yourself
You can combine several background properties into one shorthand.
background = background-color | bg-image | bg-position / bg-size | repeat-style | attachment | box;
Try it yourself