HTML is a useful tool to use if you want to add images to your web page. However, if you want to insert a background image in HTML, you need both HTML and CSS. In this article, know how to insert a background image in HTML.

HTML and CSS

HTML means Hypertext Markup Language. It is a code that commands the browser on which elements should be shown on a web page.

CSS, on the other hand, means Cascading Style Sheets, and it is used to make changes to the layout and appearance of a web page.

In order to insert a background image in HTML, you need a good background image to use for your page.

Setting Up the Files

  1. On your PC, create a folder with a name and make sure it’s easy to find later.
  2. Put the background image inside the folder.
  3. Create an HTML file. To do this, simply open a text editor and create a new file. Name the file “index.html”.

Writing the html file

  1. Copy the HTML code below:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>

<style>
body {
background-image: url(” “);
}

</style>

</head>

<body>

</body>
</html>

2. Paste the code into the index.html file.

3. In the HTML file, find the line “background-image: url(” “);”. Then, type the image’s file name. Include the image’s file extension. After, save the HTML file.

Reviewing the html file

  1. Open the file in the web browser. To do this, simply right-click on the file and then select “Open with”. You can select any web browser of your preference.
  2. In the text editor, insert “Hello World!” between the two <body> tags.
  3. Reload the browser to see the text inserted on top of the background image.

Understanding the html code

  1. Understand the HTML code. The HTML code comes with open and closed tags.
  2. Every HTML page should start with <!DOCTYPE html>.
  3. The <title> tag appears on the title bar of the browser. It also appears on the browser tab.
  4. The <style> tag includes the CSS content.
  5. The <body> tag includes written texts.

understanding the css code

The CSS code that comes between the <style tag> commands the browser to add a background image to the body with a specific name.

Follow this guideline to successfully add a background image. With the right knowledge, it’s easy to learn how to insert a background image in HTML.

Leave a Reply

Your email address will not be published. Required fields are marked *