body element is the container for all renderable aspects of a document. This is the place where authors throw all the elements and contents their visitors will reach. The
body element is part of the basic structure of a document.
body element had several presentational attributes in previous versions of HTML. These attributes have been deprecated before in favor of style sheets, and are now obsolete in HTML5. Authors are adviced to avoid their use.
The next example shows the basic structure of a webpage, including the
<!DOCTYPE html> <html> <head> <title>The beauty of life</title> </head> <body> <h1>The beauty of life</h1> <p>This morning I woke up feeling different...</p> </body> </html>
The default color for regular text inside the element.
This attribute was declared oblsolete in HTML5 for being merely presentaional in nature. Its use is no longer valid and authors are adviced to replace it with style sheets.
A color to fill the background of the element.
bgcolor attribute has been removed from the HTML5 standard because of its presentational nature. Its results can be perfectly achieved with style sheets.
The URL of an image that will be used to cover the background of the element.
This attribute has become obsolete in HTML5 for being presentational in nature and its use is no longer valid. Authors should replace it with style sheets declarations.
The default color of the text in all links contained by the element.
link attribute has become oblsolete in HTML5 due to its presentaional nature. The same results can be achieved by using style sheets.
The default color for links inside the element, that have already been visited.
This attribute became obsolete in the HTML5 stadard for being purely presentaional. Its results can be easily achieved using style sheet declarations.
The default color that all a elements contained by this element will take when the mouse is over them.
This attribute has become obsolete in HTML5 because of its presentational nature and, therefore, its use is no longer valid. Authors should replace it with style sheets declarations.
For information about global attributes refer to this list of global attributes in HTML5.
The user has just printed the document.
<body onafterprint="alert('Document printed successfully!');">
The user has requested the document to be printed. This event fires exactly before the document is printed and may be used to confirm, delay or cancel the process.
<body onbeforeprint="alert('Document is being sent to the printer!');">
The document is about to be unloaded (closed, removed). This event fires exactly before the document gets closed and may be used to confirm or delay the process.
Browsers will commonly use the return value of the function specified in this attribute to build the dialog box that will allow users to confirm or cancel the unload of the document.
<body onbeforeunload="return 'Changes to the form will be lost. Are you sure you want to leave?';">
The part of the URL after the hash symbol ("#") has changed.
The part of the URL after the hash symbol ("#") refers to a part or section of the pointed document. Thanks to this feature, users can, for example, follow a link directly to a section of the document.
<body onhashchange="alert('Currently viewing section: ' + location.hash);">
The preferred language of the user has changed.
<body onlanguagechange="adaptToLanguageChange(); alert('The language of the document has changed!');">
The current document has received a message.
In HTML5, documents and Web Workers have the possibility to send and recieve messages between each other. This opens a comunication channel between documents that can become very useful in web applications.
<body onmessage="alert('Message received from another document: ' + event.data);">
The network connection has been lost.
This event can be very useful in web applications that depend on the network connection to work properly. These applications can take measures to mitigate the problems caused by a connection loss or inform the user about such drawbacks.
<body onoffline="alert('Connection to the Internet has been lost!');">
The network connection has been restablished.
This event can be very useful in web applications that depend on the network connection to work properly. These applications can restart operations when this event is fired.
<body ononline="alert('Connection to the Internet has been restablished!');">
The current document has been removed form visibility during a session history traversal (a backward/forward navigation).
<body onpagehide="alert('You have moved on to another document in the sesion history');">
The current document has been shown during a session history traversal (a backward/forward navigation or refresh).
<body onpageshow="alert('You've arrived to this document of the session history!');">
There's been a change of documents in the session history. This event is most commonly triggered by a backward/forward navigation.
<body onpopstate="alert('You have moved from one document to another in the session history!');">
A previously-unhandled promise rejection becomes handled.
The data in a Web Storage area has changed.
Web Storage has been introduced in HTML5 as a replacement for cookies. It allows websites to store information in the visitor's machine and access it from any other document within the same website. Web Storage outperforms cookies in security, speed and capacity.
A promise rejection goes unhandled.
The document is being removed or closed.
This event fires when the document has already begun closing, which prevents delays or requests for confirmations. Authors trying to prevent the closing of the document should consider using the
<body onunload="updateStorage('Unsaved fields');">
For information about global events refer to this list of global events in HTML5.