tadam logo

HTML <body> background Attribute

Example

Specify a background image for an HTML document:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
a{ color: #ffffff; font-weight:bold;}
</style>
</head>
<body background="/images/13-red-snapper-665.gif"  style="color:#ffffff;">

<p><a href="http://Xhtml.co.il">Visit Xhtml.co.il!</a></p>

<p>The background attribute was deprecated in HTML 4, and is not supported in HTML 4.01 Strict DTD or in XHTML 1.0 Strict DTD. Use CSS instead.</p>

</body>
</html>
The output of the code above will be:

Compatibility Notes

The background attribute of <body> is deprecated, and is not supported in HTML 4.01 Strict / XHTML 1.0 Strict DTD.

A deprecated element or attribute is one that has been outdated.
Deprecated elements may become obsolete in the future, but browsers should continue to support deprecated elements for backward compatibility.

Use CSS instead.

CSS syntax: <body style="background-image:url(/images/13-red-snapper-665.gif);>

CSS Example: Add a background image to a document

In our CSS tutorial you can find more details about the background-image property.

Definition and Usage

The background attribute specifies a background image for a document.

Browser Support

The background attribute supported in all major browsers

Syntax

<body background="value">

Attribute Values

ValueDescription
URLThe URL of the background image.

Possible values:

  • An absolute URL - points to another web site (like href="http://example.com/bgimage.gif")
  • A relative URL - points to a file within a web site (like href="/images/bgimage.gif")
Was this information helpful?
   

Comments