
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
Setting Background Image using CSS
The CSS background-image property is used to set an image as a background for the selected element.
Syntax
The syntax of CSS background-image property is as follows −
Selector { background-image: /*value*/ }
The following examples illustrate CSS background-image property −
Example
<!DOCTYPE html> <html> <head> <style> #demo { margin: 24px; box-shadow: 0 0 5px black; padding: 20px; background-image: url("https://www.tutorialspoint.com/servlets/images/servlets.jpg"); background-origin: content-box; background-repeat: no-repeat; background-size: cover; text-shadow: 0 1px white; font-size: 1.4em; } p { box-shadow: 0 0 5px grey; } </style> </head> <body> <h2>Learn Python Blockchain</h2> <div id="demo"> <p>Servlets are programs that run on a Web or Application server and act as a middle layer between a requests coming from a Web browser or other HTTP client and databases or applications on the HTTP server. Using Servlets, you can collect input from users through web page forms, present records from a database or another source, and create web pages dynamically.</p> </div> </body> </html>
Output
This gives the following output −
Example
<!DOCTYPE html> <html> <head> <style> div { height: 150px; width: 150px; background-image: url("https://www.tutorialspoint.com/spring/images/spring-mini-logo.jpg"); border: 2px solid brown; } div > div { height: 80px; width: 80px; margin-right: 50px; background-image: url("https://www.tutorialspoint.com/images/hibernate.png"); } h1 { background-image: url("https://www.tutorialspoint.com/hibernate/images/hibernate-patterns.jpg"); background-repeat: no-repeat; color: black; } </style> </head> <body> <h1>Demo</h1> <div> <div></div> </div> </body> </html>
Output
This gives the following output −
- Related Articles
- Setting Background Position using CSS
- Setting up Background Color using CSS
- Setting Background Position in CSS
- Setting up Background Color in CSS
- CSS background-image property
- How to set background image in CSS using jQuery?
- Repeat the background image with CSS
- Specify the background image with CSS
- Setting Line Height using CSS
- Setting Text Alignment using CSS
- Setting Text Color using CSS
- Usage of background-image property in CSS
- Set the Background Image Position with CSS
- Set background image as fixed with CSS
- Achieve Responsiveness for background image with CSS

Advertisements