FactorPad
Faster Learning Tutorials

HTML html tag

The root element of the HTML file includes all other tags. It can set the document language and specify XML conformance.
  1. About - Understand the purpose of the html tag.
  2. Syntax - Describe how it is used.
  3. Settings - View required and optional attributes plus default behaviors.
  4. Examples - Review common examples.
by Paul Alan Davis, December 26, 2017
Updated: December 20, 2018
That's how we'll get to know this essential tag. Let's get started.

Outline Back Next

~/ home  / tech  / html5  / reference  / html html tag


HTML html tag with examples

Beginner

The <html> tag is one of several important tags the developer places at the beginning of an HTML document.

HTML Tags Reference

1. About the html tag

The <html> tag is the root element, which means that all other tags (elements) are contained within its opening tag <html> and closing tag </html>. So one pair per document.

The <html> tag is normally the second line of the document, found right after the <!DOCTYPE> declaration.

2. Syntax for the html tag

The html tag is not technically required, as long as the first line is not a comment. However, in almost all HTML documents the <html> opening and closing tags are present.

While a closing <html> tag is not required, it should be used. In addition, within the opening and closing tags, there should be a <head> and <body> element.

<!DOCTYPE html> <html> <head></head> <body></body> </html>

3. Settings for the html tag

As with all tags, Global Attributes can always be set.

One such global attribute, the lang attribute is used to specify the language of the document. As an example, <html lang="es"> specifies a document written in Spanish.

Below are the 10 most common language codes.

Language ISO 639-1 Code
Arabic ar
Chinese zh
English en
French fr
German de
Indonesian id
Japanese ja
Portuguese pt
Russian ru
Spanish es
For a complete list of languages see the List of ISO 639-1 Codes on Wikipedia.

If a lang attribute is not specified, it is inherited from its parent element. The rationale for why it is specified in the first tag becomes clear. The smart developer can save time by specifying the language just once, right at the start.

Default behaviors

Each user-agent (browser) has its own stylesheet per se. This dictates how that browser styles each element by default. The Chrome browser styles the <html> element using the following specifications.

html { display: block; }

4. Examples of the html tag

Example 1 - Create an html tag for the English language

The following code establishes an HTML document with English as the written language.

<!DOCTYPE html> <html lang="en"> <head></head> <body></body> </html>
Example 2 - Optionally include instructions for XML parsers

The developer can specify whether a document is also written for XML, which is similar to HTML. This specifies that the document conforms to both markup languages. You wouldn't hear me say it, but these are also referred to as polyglot documents.

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head></head> <body></body> </html>

Other Related HTML Content

The <html> tag is paired with other essential tags that should be included in every HTML document.


What's Next?

Pair this web content with videos at our YouTube Channel. Subscribe here.

  • For the complete HTML tag list, click Outline.
  • To learn about the <!-- comment --> tag, click Back.
  • To see the <head> tag, click Next.

Outline Back Next

~/ home  / tech  / html5  / reference  / html html tag



 
 
Keywords:
html tag
html lang tag
html xmlns tag
html element
html lang element
html root tag
html tag examples
simple html code
html language
html xmlns tag example
html tag defaults
html lang attribute