How to add a background image to a web page with HTML/XHTML

The code below shows you how to add a background image to a web page with HTML/XHTML.

Note: although you can add a background image to a web page with HTML, it is recommended that you instead add a background image to a web page with CSS.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Web Development Tutorials.com</title>
</head>
<body background="imagewebdevelopmenttutorials1w244h33.jpg">
<h1>
This web page has a background image that is set with HTML
</h1>
</body>
</html>

The code above creates the following linked web page: how to set an image as the background with HTML

Use the text editor below to practice what you have learned.

You can use the image file "imagewebdevelopmenttutorials1w244h33.jpg" to practice inserting an image into a web page.

Free Website Templates

Free Web Tools

Recommended Websites