Scroll to top
Read Time: 2 min

The html element is the root of an HTML document. This element is required to create a valid page.

Example

Syntax

1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
  <title>My Favorite Foods</title>
5
</head>
6
<body>
7
  <h1>My Favorite Foods</h1>
8
  <p>Eu non fugiat sunt cupidatat consequat. Dolore nostrud id tempor aute pariatur sit veniam pariatur velit voluptate voluptate excepteur reprehenderit.</p>
9
</body>
10
</html>

Browser Support

The html element is supported in all modern browsers. Read more on caniuse.com.

Attributes

An html element supports Global Attributes in HTML. Global Attributes are common to all HTML elements and can be used on all of them (though they may not have much of an effect on some of them).

Additional attributes:
  • manifest: Specifies the URI of a resource manifest indicating resources that should be cached locally.
  • version: Specifies the version of the HTML Document Type Definition that governs the current document. This attribute is not necessary.
  • xmlns: Specifies the XML Namespace of the document. The default value is "https://www.w3.org/1999/xhtml"

Don’t Forget the lang Attribute

The HTML lang attribute should always be included on a web page’s <html> element. It’s used to specify the language of text content within the document. This helps search engines deliver search results in the correct language, and helps screen readers switch language profiles for correct accents and pronunciation.

In the syntax example above you’ll see <html lang="en"> which uses the two-letter ISO code for English as the language.

Failing to include the lang attribute on the opening html tag will trigger a warning when validating the document.

screenshot of validation warning when omitting the lang attribute on html elementscreenshot of validation warning when omitting the lang attribute on html elementscreenshot of validation warning when omitting the lang attribute on html element

Content

The html content model is limited and only contains support for the <head> and <body> elements.

Did you know? The first version of HTML was written by Tim Berners-Lee in 1993. The widest adoption of the language occurred when HTML was updated to version 4.0.1. Today most modern browsers and websites run the HTML5 specification.

Learn More

Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.