- : 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!
- 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:
- HTML Styles — CSS
- CSS = Styles and Colors
- What is CSS?
- Using CSS
- Inline CSS
- Example
- A Blue Heading
- Internal CSS
- Example
- This is a heading
- External CSS
- Example
- This is a heading
- «styles.css»:
- CSS Colors, Fonts and Sizes
- Example
- This is a heading
- CSS Border
- Example
- CSS Padding
- Example
- CSS Margin
- Example
- Link to External CSS
- Example
- Example
- Example
- Chapter Summary
- HTML Exercises
- HTML Style Tags
: 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.
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.
HTML Styles — CSS
CSS saves a lot of work. It can control the layout of multiple web pages all at once.
CSS = Styles and Colors
What is CSS?
Cascading Style Sheets (CSS) is used to format the layout of a webpage.
With CSS, you can control the color, font, the size of text, the spacing between elements, how elements are positioned and laid out, what background images or background colors are to be used, different displays for different devices and screen sizes, and much more!
Tip: The word cascading means that a style applied to a parent element will also apply to all children elements within the parent. So, if you set the color of the body text to «blue», all headings, paragraphs, and other text elements within the body will also get the same color (unless you specify something else)!
Using CSS
CSS can be added to HTML documents in 3 ways:
- Inline — by using the style attribute inside HTML elements
- Internal — by using a element in the section
- External — by using a element to link to an external CSS file
The most common way to add CSS, is to keep the styles in external CSS files. However, in this tutorial we will use inline and internal styles, because this is easier to demonstrate, and easier for you to try it yourself.
Inline CSS
An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the element to blue, and the text color of the
element to red:
Example
A Blue Heading Internal CSS
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the section of an HTML page, within a element.
The following example sets the text color of ALL the elements (on that page) to blue, and the text color of ALL the
elements to red. In addition, the page will be displayed with a «powderblue» background color:
Example
This is a heading
This is a paragraph.
External CSS
An external style sheet is used to define the style for many HTML pages.
To use an external style sheet, add a link to it in the section of each HTML page:
Example
This is a heading
This is a paragraph.
The external style sheet can be written in any text editor. The file must not contain any HTML code, and must be saved with a .css extension.
Here is what the «styles.css» file looks like:
«styles.css»:
Tip: With an external style sheet, you can change the look of an entire web site, by changing one file!
CSS Colors, Fonts and Sizes
Here, we will demonstrate some commonly used CSS properties. You will learn more about them later.
The CSS color property defines the text color to be used.
The CSS font-family property defines the font to be used.
The CSS font-size property defines the text size to be used.
Example
Use of CSS color, font-family and font-size properties:
This is a heading
This is a paragraph.
CSS Border
The CSS border property defines a border around an HTML element.
Tip: You can define a border for nearly all HTML elements.
Example
Use of CSS border property:
CSS Padding
The CSS padding property defines a padding (space) between the text and the border.
Example
Use of CSS border and padding properties:
CSS Margin
The CSS margin property defines a margin (space) outside the border.
Example
Use of CSS border and margin properties:
Link to External CSS
External style sheets can be referenced with a full URL or with a path relative to the current web page.
Example
This example uses a full URL to link to a style sheet:
Example
This example links to a style sheet located in the html folder on the current web site:
Example
This example links to a style sheet located in the same folder as the current page:
You can read more about file paths in the chapter HTML File Paths.
Chapter Summary
- Use the HTML style attribute for inline styling
- Use the HTML element to define internal CSS
- Use the HTML element to refer to an external CSS file
- Use the HTML element to store and elements
- Use the CSS color property for text colors
- Use the CSS font-family property for text fonts
- Use the CSS font-size property for text sizes
- Use the CSS border property for borders
- Use the CSS padding property for space inside the border
- Use the CSS margin property for space outside the border
Tip: You can learn much more about CSS in our CSS Tutorial.
HTML Exercises
HTML Style Tags
Tag | Description |
---|---|
Defines style information for an HTML document | |
Defines a link between a document and an external resource |
For a complete list of all available HTML tags, visit our HTML Tag Reference.