Monday, 13 June 2016

HTML body tag


HTML: <body> tag

This HTML tutorial explains how to use the HTML element called the <body> tag with syntax and examples.

Description

The HTML <body> tag defines the main content of the HTML document or the section of the HTML document that will be directly visible on your web page. This tag is also commonly referred to as the <body> element.

Syntax

In HTML, the syntax for the <body> tag is:
<body>
</body>

Attributes

In addition to the Global Attributes, the following is a list of attributes that are specific to the <bpdy> tag:
AttributeDescriptionHTML Compatibility
alignColor of text for selected hyperlinksDepreciated in HTML 4.01, Obsolete in HTML 5, use CSS
backgroundImage to be used a backgroundDepreciated in HTML 4.01, Obsolete in HTM L5, use CSS
bgcolorBackground colorDepreciated in HTML 4.01, Obsolete in HTML 5, use CSS
linkColor of text for unvisited hyperlinksDepreciated in HTML 4.01, Obsolete in HTML 5, use CSS
onafterprintFunction to call user has printed documentHTML 5
onbeforeprintFunction to call when user requests document to be printedHTML 5
onbeforeunloadFuntion to call when document is to be unloadedHTML 5
onblurFunction to call when document has lost focusHTML 5
onerrorFunction to call when document failsHTML 5
onfocusFunction to call when document has focusHTML 5
onhaschangeFunction to call when fragment identifier portion of document's address has changedHTML 5
onloadFunction to call when document has loadedHTML 5
onmessageFunction to call when the document received a messageHTML 5
onofflineFunction to call when Network communication failsHTML 5
ononlineFunction to call when Network communication is restoredHTML 5
onpopstateFunction to call when user navigated session historyHTML 5
onredoFunction to call when user moved forward in undo historyHTML 5
onresizeFunction to call when document was resizedHTML 5
onstorageFunction to call when storage area changedHTML 5
onundoFunction to call when user moved backward in undo historyHTML 5
onunloadFunction to call when document is being unloadedHTML 5
textForeground color of textDepreciated in HTML 4.01, Obsolete in HTML 5, use CSS
vlinkColor of text for visited hyperlinksDepreciated in HTML 4.01, Obsolete in HTML 5, use CSS

Note

  • The HTML <body> element is found within the <html> tag.
  • The most common elements to be placed in the HTML <body> tag are: <h1><p><div><table> tags.

Browser Compatibility

The <body> tag has basic support with the following browsers:
  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • IE Phone
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the <body> tag below, exploring examples of how to use the <body> tag in HTML 5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.

HTML 5 Document

If you created a new web page in HTML 5, your <body> tag might look like this:
<!doctype html>
<html>

<head>
<meta charset="UTF-8">
<title>HTML 5 Example by www.techonthenet.com</title>
</head>

<body>
<h1>Heading</h1>
<p>This is the content.</p>
</body>
</html>
In this HTML 5 Document example, the <body> tag contains two elements - a heading found in the <h1> tag and a paragraph found in the <p> tag.

HTML 4.01 Transitional Document

If you created a new web page in HTML 4.01 Transitional, your <body> tag might look like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>HTML 4.01 Transitional Example by www.techonthenet.com</title>
</head>

<body>
<h1>Heading</h1>
<p>This is the content.</p>
</body>
</html>
In this HTML 4.01 Transitional Document example, the <body> tag contains two elements - a heading found in the <h1> tag and a paragraph found in the <p> tag.

XHTML 1.0 Transitional Document

If you created a new web page in XHTML 1.0 Transitional, your <body> tag might look like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>XHTML 1.0 Transitional Example</title>
</head>

<body>
<h1>Heading</h1>
<p>This is the content.</p>
</body>
</html>
In this XHTML 1.0 Transitional Document example, the <body> tag contains two elements - a heading found in the <h1> tag and a paragraph found in the <p> tag.

XHTML 1.0 Strict Document

If you created a new web page in XHTML 1.0 Strict, your <body> tag might look like this:
<!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">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>XHTML 1.0 Strict Example by www.techonthenet.com</title>
</head>

<body>
<h1>Heading</h1>
<p>This is the content.</p>
</body>
</html>
In this XHTML 1.0 Strict Document example, the <body> tag contains two elements - a heading found in the <h1> tag and a paragraph found in the <p> tag.

XHTML 1.1 Document

If you created a new web page in XHTML 1.1, your <body> tag might look like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>XHTML 1.1 Example by www.techonthenet.com</title>
</head>

<body>
<h1>Heading</h1>
<p>This is the content.</p>
</body>
</html>
In this XHTML 1.1 Document example, the <body> tag contains two elements - a heading found in the <h1> tag and a paragraph found in the <p> tag.

No comments:

Post a Comment