- : The Document Body element
- Attributes
- Examples
- Result
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- This is a heading
- Browser Support
- Global Attributes
- Event Attributes
- More Examples
- Example
- Hello world!
- Example
- Hello world!
- Example
- Hello world!
- Example
- Example
- Example
- Related Pages
- Default CSS Settings
- Example
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
- Tag in HTML
- HTML Tag
- Tag Specific Attributes
- Window Event Attributes
- HTML Tag Usage
- Supported Browsers
- Summary
- HTML Tag
- Syntax
- Example of the HTML tag:
- Result
- Example of the HTML tag used with the CSS color and line-height properties:
- Attributes
- How to style tag?
- Common properties to alter the visual weight/emphasis/size of text in tag:
- Coloring text in tag:
- Text layout styles for tag:
- Other properties worth looking at for tag:
: The Document Body element
The HTML element represents the content of an HTML document. There can be only one element in a document.
Attributes
This element includes the global attributes.
Color of text for hyperlinks when selected. Do not use this attribute! Use the CSS color property in conjunction with the :active pseudo-class instead.
URI of an image to use as a background. Do not use this attribute! Use the CSS background property on the element instead.
Background color for the document. Do not use this attribute! Use the CSS background-color property on the element instead.
The margin of the bottom of the body. Do not use this attribute! Use the CSS margin-bottom property on the element instead.
The margin of the left of the body. Do not use this attribute! Use the CSS margin-left property on the element instead.
Color of text for unvisited hypertext links. Do not use this attribute! Use the CSS color property in conjunction with the :link pseudo-class instead.
Function to call after the user has printed the document.
Function to call when the user requests printing of the document.
Function to call when the document is about to be unloaded.
Function to call when the document loses focus.
Function to call when the document fails to load properly.
Function to call when the document receives focus.
Function to call when the fragment identifier part (starting with the hash ( ‘#’ ) character) of the document’s current address has changed.
Function to call when the preferred languages changed.
Function to call when the document has finished loading.
Function to call when the document has received a message.
Function to call when network communication has failed.
Function to call when network communication has been restored.
Function to call when the user has navigated session history.
Function to call when the user has moved forward in undo transaction history.
Function to call when the document has been resized.
Function to call when the storage area has changed.
Function to call when the user has moved backward in undo transaction history.
Function to call when the document is going away.
The margin of the right of the body. Do not use this attribute! Use the CSS margin-right property on the element instead.
Foreground color of text. Do not use this attribute! Use CSS color property on the element instead.
The margin of the top of the body. Do not use this attribute! Use the CSS margin-top property on the element instead.
Color of text for visited hypertext links. Do not use this attribute! Use the CSS color property in conjunction with the :visited pseudo-class instead.
Examples
html lang="en"> head> title>Document titletitle> head> body> p> The code><body>code> HTML element represents the content of an HTML document. There can be only one code><body>code> element in a document. p> body> html>
Result
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jun 13, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.
This is a heading
This is a paragraph.
The element contains all the contents of an HTML document, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
Note: There can only be one element in an HTML document.
Browser Support
Global Attributes
Event Attributes
More Examples
Example
Add a background image to a document (with CSS):
Hello world!
Visit W3Schools.com!
Example
Set the background color of a document (with CSS):
Hello world!
Visit W3Schools.com!
Example
Set the color of text in a document (with CSS):
Hello world!
This is some text.
Visit W3Schools.com!
Example
Set the color of unvisited links in a document (with CSS):
Example
Set the color of active links in a document (with CSS):
Example
Set the color of visited links in a document (with CSS):
Related Pages
Default CSS Settings
Most browsers will display the element with the following default values:
Example
body <
display: block;
margin: 8px;
>
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
Tag in HTML
In this article, you will learn about the HTML element called the tag. The body tag contains all the main content of the webpage such as headings, paragraphs, images, tables etc. It is always enclosed within the tag. Everything you see on the web browser will be present inside the tag.
HTML Tag
We all know that HTML is basically used to build websites that are available on the internet. HTML consists of series of elements like tag tag, etc that are used to structure the web page. One such element that is a home for all the other contents of the webpage such as headings, paragraphs, images, tables etc is HTML Tag.
All the content inside the tag is only visible on the webpage.
For example
As shown in the example, the
tag is always enclosed within the tag and there can be only one tag in the whole webpage. It is usually present after the tag. The content in the tag is written between the opening ( ) and closing ( ) tags.Tag Specific Attributes
tag has some attributes that change the way the web pages looks. Let’s learn about a few of them.
Attribute | Description |
---|---|
bgcolor | Colour of the Background of your page |
alink | Color of text for links |
background | Image to be used as a background |
link | Color of text for links that are not visited |
vlink | Color of text for visited links |
text | Color of the text on your webpage |
margins | Used to add margins to the webpage |
Window Event Attributes
There are some window event attributes that are script based and used within the tag.
Few examples are given below for your reference.
Attribute | Description |
---|---|
ononline | Script triggered when the browser starts to work online |
onoffline | Script triggered when the browser starts to work offline |
onload | Script triggered when the page is completely loaded |
onerror | Script triggered when an error occurs |
onpageshow | Script triggered when a user visits a page |
onresize | Script triggered when the browser window is resized |
HTML Tag Usage
Below is an example of basic structure of a webpage with tag.
Explanation
- The element contains all the contents of the webpage like the heading, paragraph, images, tables etc. Here element specifies a heading and
element specifies a paragraph.
- The elements contains all the contents of the webpage.
- The element contains additional information about the HTML page like the page title.
- The element specifies a title for the webpage which is shown in the browser’s window.
Below is another example tag usage with bgcolor attribute.
Explanation
The HTML bgcolor attribute is used to set the background color of an HTML element.
The Atrribute value can be anyone of the following:
- colorname: The background color is set by using the color name. For example “yellow”
- hexnumber: The background color is set using the color hex code. For example “#0000ff” .
- rgbnumber: The background color is set by using the RGB code. For example: “RGB(0, 153, 0)” .
Supported Browsers
HTML tag is supported by all major web browsers. HTML Tag is supported by all major web browsers as it is the main html element.
Below is the list of some major supported browsers.
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
- Microsoft Edge
Summary
- The HTML tag contains all the main content of the webpage such as headings, paragraphs, images, tables etc.
- All the content inside the tag is only visible on the webpage.
- HTML Tag has attributes like bgcolor, text etc that change the way webpage looks.
- HTML Tag is supported by all major web browsers as it is the main html element.
HTML Tag
The tag defines a web page content (text, images, links, etc.). It is placed inside the element, after the element. In an HTML document, we can use only one tag.
Commonly, a list of content-specific CSS classes is placed within the element allowing JavaScript developers and designers to target pages easily. Even if these classes are not used, they won’t cause any problems.
Syntax
The
tag comes in pairs. The content is written between the opening () and closing () tags.Example of the HTML tag:
html> html> head> title>Title of the document title> head> body> p>Content of the document p> body> html>
Result
Example of the HTML tag used with the CSS color and line-height properties:
html> html> head> title>Title of the document title> style> body < color: #444444; line-height: 1.5; > style> head> body> h1>HTML body tag example h1> p>Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. p> body> html>
Attributes
Attribute | Value | Description |
---|---|---|
alink | color | Defines the color of the active link. Not used in HTML5. |
background | URL | Defines the background image. Not used in HTML5. |
bgcolor | color | Defines the background color. Not used in HTML5. |
link | color | Defines the color of unvisited links. Not used in HTML5. |
text | color | Defines the color of the text in a document. Not used in HTML5. |
vlink | color | Defines the color of the visited link. Not used in HTML5. |
How to style tag?
Common properties to alter the visual weight/emphasis/size of text in tag:
- CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit.
- CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element.
- CSS font-size property sets the size of the font.
- CSS font-weight property defines whether the font should be bold or thick.
- CSS text-transform property controls text case and capitalization.
- CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style.
Coloring text in tag:
- CSS color property describes the color of the text content and text decorations.
- CSS background-color property sets the background color of an element.
Text layout styles for tag:
- CSS text-indent property specifies the indentation of the first line in a text block.
- CSS text-overflow property specifies how overflowed content that is not displayed should be signalled to the user.
- CSS white-space property specifies how white-space inside an element is handled.
- CSS word-break property specifies where the lines should be broken.
Other properties worth looking at for tag:
- CSS text-shadow property adds shadow to text.
- CSS text-align-last property sets the alignment of the last line of the text.
- CSS line-height property specifies the height of a line.
- CSS letter-spacing property defines the spaces between letters/characters in a text.
- CSS word-spacing property sets the spacing between words.