HTML Background Images
HTML stands for HyperText Markup Language. It is used to design or create web pages using a markup language. It is a combination of Hypertext and Markup language. Here, hypertext defines the link between the web pages whereas markup language is used to define the text document within tag which defines the structure of web pages. In HTML, we can make our web pages look more attractive and captivating by adding a background image to our HTML page. So, we can add background images in two different ways:
- Add a background image using the background image attribute inside the <body> tag.
- Add background image using the HTML style attribute.
In this article, we will learn these two methods for adding background images to web pages.
1. Using the background-image attribute inside the <body> tag
In this method we will add a background image is using the background image attribute inside the <body> tag.
2. Using the HTML style attribute.
In this method, we will add a background image using the HTML style attribute for a particular element in the webpage.
<div style=”background-image: url(‘img.jpg’);”>
In the above example we can see that there is no background image for the heading “Welcome to GeeksforGeeks”, but we have a background image for the div containing paragraphs.
How repeated background image?
In HTML, if the image is small in size as compared to the element then the image repeats itself horizontally and vertically. It repeats until it reaches the end of the element. If you don’t want to repeat the image then set the value of background-repeat property to no-repeat. Let us discuss this concept with the help of an example:
Attention reader! All those who say programming isn’t for kids, just haven’t met the right mentors yet. Join the Demo Class for First Step to Coding Course, specifically designed for students of class 8 to 12.
The students will get to learn more about the world of programming in these free classes which will definitely help them in making a wise career choice in the future.