-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
CSS Basics
CSS Styling Properties
CSS Box Model
CSS Margin
CSS Padding
CSS Borders
CSS Outline
CSS Height/Width
CSS Max-width
CSS Display
CSS Position
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Box Sizing
CSS Text
CSS Fonts
CSS Icons
CSS Text Effects
CSS Web Fonts
CSS Colors
CSS Backgrounds
CSS Color Keywords
CSS Gradients
CSS Shadows
CSS Links
CSS Lists
CSS Tables
CSS Advanced Selectors & Features
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Attribute Selectors
CSS Specificity
CSS !important
CSS Units
CSS Variables
CSS @property
CSS Math Functions
CSS Media and Image Styling
CSS Image Styling
CSS Image Centering
CSS Image Filters
CSS Image Shapes
CSS object-fit
CSS object-position
CSS Masking
CSS Layout Techniques
CSS Website Layout
CSS Navigation Bar
CSS Dropdowns
CSS Image Gallery
CSS Counters
CSS Pagination
CSS Multiple Columns
CSS User Interface
CSS Flexbox
CSS Grid
CSS Responsive Design (RWD)
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.
CSS Basics
CSS Styling Properties
CSS Box Model
CSS Margin
CSS Padding
CSS Borders
CSS Outline
CSS Height/Width
CSS Max-width
CSS Display
CSS Position
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Box Sizing
CSS Text
CSS Fonts
CSS Icons
CSS Text Effects
CSS Web Fonts
CSS Colors
CSS Backgrounds
CSS Color Keywords
CSS Gradients
CSS Shadows
CSS Links
CSS Lists
CSS Tables
CSS Advanced Selectors & Features
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Attribute Selectors
CSS Specificity
CSS !important
CSS Units
CSS Variables
CSS @property
CSS Math Functions
CSS Media and Image Styling
CSS Image Styling
CSS Image Centering
CSS Image Filters
CSS Image Shapes
CSS object-fit
CSS object-position
CSS Masking
CSS Layout Techniques
CSS Website Layout
CSS Navigation Bar
CSS Dropdowns
CSS Image Gallery
CSS Counters
CSS Pagination
CSS Multiple Columns
CSS User Interface
CSS Flexbox
CSS Grid
CSS Responsive Design (RWD)