1. html
  2. /tags
  3. /html

<html>

Definition

The HTML <html> element is the top-level element that defines the beginning and end of an HTML document. It serves as the container for all other HTML elements and provides the basic structure for an HTML page.

Every HTML document must contain an opening and closing <html> tag. The opening tag is written as <html> and the closing tag is written as </html>. All other HTML elements should be placed within the <html> tags.

Examples

Here's an example of what a basic HTML document with the <html> element might look like:

<!DOCTYPE html>
<html>
  <head>
    <title>My HTML Page</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
    <p>This is my first HTML page.</p>
  </body>
</html>

In this example, the <html> element is the first element in the document and contains two child elements: the <head> element and the <body> element. The <head> element contains metadata about the document, such as the document's title, while the <body> element contains the visible content of the document.

Attributes

This element's attributes include the global attributes.

AttributeDescriptionDeprecated?
langSpecifies the primary language used in the content of the HTML document. It takes a language code as its value, such as "en" for English or "es" for Spanish. For example: <html lang="en">No
dirSpecifies the base direction of text in the HTML document, either left-to-right (default) or right-to-left. It takes "ltr" for left-to-right or "rtl" for right-to-left as its value. For example: <html dir="rtl">No
xmlnsSpecifies the XML namespace in which the document is written. Used in XHTML documents, which are HTML documents that are also well-formed XML documentsNo

Best Practices

  • Always include an opening and closing <html> tag in your HTML document. All other HTML elements should be nested within the <html> tags.
  • Use the lang attribute to specify the primary language used in the content of the HTML document. This can help search engines and screen readers to better understand the content of the document.
  • Use the dir attribute to specify the base direction of text in the HTML document if the content is in a language that is written right-to-left.
  • Use the correct doctype declaration at the beginning of your document to ensure that it is interpreted correctly by browsers. For example, use <!DOCTYPE html> for HTML5 documents.
  • Use the xmlns attribute in XHTML documents to declare the XML namespace in which the document is written.

Accessibility Considerations

  • Use the lang attribute to specify the primary language used in the content of the HTML document. This can help assistive technologies, such as screen readers, to correctly pronounce and understand the content.
  • Use the dir attribute to specify the base direction of text in the HTML document if the content is in a language that is written right-to-left.
  • Make sure the document is well-structured and organized using appropriate HTML elements such as headings, paragraphs, lists, and tables. This helps assistive technologies and keyboard-only users to navigate and understand the content.
  • Ensure that all images and media have alternative text (alt text) that describes the content or function of the image or media. This helps users who are unable to see the image or media to understand its purpose.
  • Use descriptive and meaningful labels for form controls, such as input fields and buttons, to help users understand their purpose.
  • Provide text-based alternatives for non-text content, such as videos and audio files, in order to make them accessible to users who cannot see or hear them.
  • Make sure that the document is navigable using only the keyboard, as some users may not be able to use a mouse or other pointing device.
  • Ensure that the document is compatible with assistive technologies, such as screen readers and braille displays.
  • Test the document using accessibility tools and guidelines, such as the Web Content Accessibility Guidelines (WCAG), to ensure that it meets the requirements for accessibility.

Browser Compatibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesYesYesYes