-
Hajipur, Bihar, 844101
CSS Background properties allow you to control the background appearance of elements — including colors, images, positioning, repeating, attachment, and more.
Property | Description |
---|---|
background-color |
Sets background color |
background-image |
Sets a background image |
background-repeat |
Repeats the background image |
background-position |
Sets the position of the background image |
background-size |
Specifies size of background image |
background-attachment |
Fixes background while scrolling |
background (shorthand) |
Combines all background properties |
background-color
Sets the background color of an element.
div {
background-color: lightblue;
}
background-image
Adds an image as the background.
div {
background-image: url('background.jpg');
}
background-repeat
Defines how the image repeats:
background-repeat: repeat; /* default */
background-repeat: no-repeat; /* no repeating */
background-repeat: repeat-x; /* horizontal */
background-repeat: repeat-y; /* vertical */
background-position
Sets the starting position of the image:
background-position: top right;
You can use values like left
, right
, center
, bottom
, or in px/%
.
background-size
Specifies the size of the background image:
background-size: cover; /* Fill entire element */
background-size: contain; /* Fit within element */
background-size: 100px 200px; /* Custom size */
background-attachment
Controls scroll behavior:
background-attachment: scroll; /* default */
background-attachment: fixed; /* image stays in place */
background-attachment: local;
background
(Shorthand)div {
background: url('img.jpg') no-repeat center center / cover;
}
🟢 Combines all background properties in one line.
Q1. Set a yellow background color for a div.
Q2. Add a background image named bg.jpg
.
Q3. Prevent the image from repeating.
Q4. Center the image horizontally and vertically.
Q5. Resize the background image to fully cover the div.
Q6. Fix the image in the background while scrolling.
Q7. Use a different background color for a header section.
Q8. Create a gradient overlay on a background image.
Q9. Use background-size: contain
for a logo section.
Q10. Write shorthand to apply image + color + position.
Q1: Which property sets a background color?
Q2: What is the default value for background-repeat?
Q3: Which value makes the background image scale to fill the area?
Q4: What does background-position: center center do?
Q5: Which property makes the background image not scroll with the content?
Q6: Which background-size value fits the image within its container?
Q7: Which is the correct shorthand for background?
Q8: What will background-color: transparent; do?
Q9: Which value is valid for background-position?
Q10: Which value fills the background completely without distortion?