
- CSS - Home
- CSS - Roadmap
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Types
- CSS - Measurement Units
- CSS - Selectors
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS - Cascading
- CSS - Universal Selectors
- CSS - ID Selectors
- CSS - Group Selectors
- CSS - Class Selectors
- CSS - Child Selectors
- CSS - Element Selectors
- CSS - Descendant Selectors
- CSS - General Sibling Selectors
- CSS - Adjacent Sibling Selectors
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Advanced Features
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS Interview Questions
- CSS Online Quiz
- CSS Online Test
- CSS Mock Test
- CSS - Quick Guide
- CSS - Cheatsheet
- CSS - Properties References
- CSS - Functions References
- CSS - Color References
- CSS - Web Browser References
- CSS - Web Safe Fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - background-image Property
The background-image property of CSS allows the setting of one or more background images for an element. The image url can be specified and be combined with other properties of the background to make it visually appealing.
Syntax
background-image: url('url') | none | initial | inherit;
Property Values
Value | Description |
---|---|
url | This specifies the url of the required image.For multiple images comma separated urls have to be provided. |
nope | This specifies that no image must be displayed. Default value. |
linear-gradient() | This sets the linear-gradient background-image that is defined at least 2 color from the top to the bottom. |
radial-gradient() | This sets the radial-gradient background-image that is defined at least 2 color from the center to the edge. |
initial | This sets the property to its initial value. |
inherit | This inherits the property from the parent element. |
Examples of CSS Background Image Property
Below are described some examples of the background-image property using different values.
Setting an Image as Background
The background of an image can be set by specifying the url of the required image.In the following example, the url of a flower image has been used.
Example
<!DOCTYPE html> <html> <head> <style> .background-img { background-image: url('/https/www.tutorialspoint.com/css/images/pink-flower.jpg'); background-repeat: no-repeat; width: 400px; height: 400px; position: relative; border: 5px solid black; color: white; } </style> </head> <body> <h2>CSS background-image property</h2> <div class="background-img">Image</div> </body> </html>
Multiple Images as Background
If multiple images are to be used, then the url's of the images are to be specified in the url() with comma separated values.In the following example, two different images have been used which are stacked over each other.
Example
<!DOCTYPE html> <html> <head> <style> .multiple-images { background-image: url('/https/www.tutorialspoint.com/css/images/logo.png'), url('/https/www.tutorialspoint.com/css/images/white-flower.jpg'); background-repeat: no-repeat; width: 800px; height: 700px; position: relative; border: 5px solid black; color: white; } </style> </head> <body> <h2>CSS background-image property</h2> <div class="multiple-images"></div> </body> </html>
Color Transisitions in Background
The background of an image can also be set using linear-gradient.The color transition occurs in a straight line in the specified direction.This is demonstrated in the example below.
Here, we defined the direction of the gradient 'bottom' and then the starting and ending colors 'yellow' and 'green'.
Example
<!DOCTYPE html> <html> <head> <style> .linear-gradient { background-image: linear-gradient(to bottom, yellow, green); background-repeat: no-repeat; background-position: center; width: 400px; height: 400px; position: relative; border: 5px solid black; } </style> </head> <body> <h2>CSS background image property</h2> <div class="linear-gradient"> Background image with linear gradient</div> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
background-image | 1.0 | 4.0 | 1.0 | 1.0 | 3.0 |