HTML 'body' Element Attributes

Q

What Attributes Are Allowed in the HTML Body Element?

✍: FYIcenter.com

A

XHTML 1.0 strict version does not allow some attributes that were commonly used in early versions of HTML specification. For example: "background" can be used to specify a background image, and "bgcolor" can be used to specify the background color.

Both "background" and "bgcolor" are not allowed as "body" attributes now. If you want set background image and color, you need to use the "style" attribute to specify CSS properties, as shown the tutorial example below:

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
 <head>
  <title>Style Attribute in Body Element</title>
 </head>
 <body style="background-color: #dddddd">
  <p>Hello world!</p>
 </body>
</html>

If you save the above document as style.html, and view it with Internet Explorer, you will see a gray background specified by the style attribute as shown below:
HTML body Element with CSS Style Properties

 

HTML Body Tag and Block Level Tags

⇒⇒HTML Tutorials

2017-02-20, 176👍, 0💬