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 <body> tag:
Attribute | Description | HTML Compatibility |
---|---|---|
alink | Color of text for selected hyperlinks | Depreciated in HTML 4.01, Obsolete in HTML5, use CSS |
background | Image to be used a background | Depreciated in HTML 4.01, Obsolete in HTM L5, use CSS |
bgcolor | Background color | Depreciated in HTML 4.01, Obsolete in HTML5, use CSS |
link | Color of text for unvisited hyperlinks | Depreciated in HTML 4.01, Obsolete in HTML5, use CSS |
onafterprint | Function to call user has printed document | HTML5 |
onbeforeprint | Function to call when user requests document to be printed | HTML5 |
onbeforeunload | Funtion to call when document is to be unloaded | HTML5 |
onblur | Function to call when document has lost focus | HTML5 |
onerror | Function to call when document fails | HTML5 |
onfocus | Function to call when document has focus | HTML5 |
onhaschange | Function to call when fragment identifier portion of document's address has changed | HTML5 |
onload | Function to call when document has loaded | HTML5 |
onmessage | Function to call when the document received a message | HTML5 |
onoffline | Function to call when Network communication fails | HTML5 |
ononline | Function to call when Network communication is restored | HTML5 |
onpopstate | Function to call when user navigated session history | HTML5 |
onredo | Function to call when user moved forward in undo history | HTML5 |
onresize | Function to call when document was resized | HTML5 |
onstorage | Function to call when storage area changed | HTML5 |
onundo | Function to call when user moved backward in undo history | HTML5 |
onunload | Function to call when document is being unloaded | HTML5 |
text | Foreground color of text | Depreciated in HTML 4.01, Obsolete in HTML5, use CSS |
vlink | Color of text for visited hyperlinks | Depreciated in HTML 4.01, Obsolete in HTML5, 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)
- Edge Mobile
- 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 HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.
Advertisements