An HTML page can still validate even if the <html>
and <body>
tags are omitted.
<!DOCTYPE html> <head> <title>Page Title</title> </head> <h1>This is a heading</h1> <p>This is a paragraph.</p> |
It’s highly recommended to include the <html>
and <body>
tags, as omitting them may cause errors in older browsers and potentially crash DOM and XML software.
The HTML <head> tag is optional.
Browsers automatically append all elements before <body> to a default <head> element if the <head> tag is omitted.
Example
<!DOCTYPE html> <html> <title>Page Title</title> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> </html> |
Nevertheless, we advise employing the <head> tag.
Closing empty elements in HTML is optional.
<meta charset=”utf-8″> |
<meta charset=”utf-8″ /> |
If you anticipate XML/XHTML software accessing your page, ensure to include the closing slash (/) as it’s mandatory in XML and XHTML.
Including the lang attribute within the <html> tag is essential as it declares the language of the web page, aiding search engines and browsers in proper interpretation.
Example
<!DOCTYPE html> <html lang=”en-us”> <head> <title>Page Title</title> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> </html> |