FREE E LEARNING PLATFORM
INTROIMAGESTABLESLISTFORMSRESPONSIVE
 

HTML Head


The HTML <head> Element

The <head> element is a container for metadata (data about data).

HTML metadata is data about the HTML document. Metadata is not displayed.

Metadata typically define document title, styles, links, scripts, and other meta information.

The following tags describe metadata: <title>, <style>, <meta>, <link>, <script>, and <base>.


Omitting <html> and <body>?

In the HTML5 standard, the <html> tag, the <body> tag, and the <head> tag can be omitted.

The following code will validate as HTML5:

Example

<!DOCTYPE html>
<title>Page Title</title>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>
Try it Yourself »
Note Noidatut does not recommend omitting the <html> and <body> tags.

The <html> element is the document root. It is the recommended place for specifying the page language:

<!DOCTYPE html>
<html lang="en-US">

Declaring a language is important for accessibility applications (screen readers) and search engines.

Omitting <html> and <body> can crash badly-written DOM/XML software.

Finally, omitting <body> can produce errors in older browsers (IE9).


Omitting <head>

In the HTML5 standard, the <head> tag can also be omitted.

By default, browsers will add all elements before <body>, to a default <head> element.

You can reduce the complexity of HTML, by omitting the <head> tag:

Example

<!DOCTYPE html>
<html>
<title>Page Title</title>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>
Try it Yourself »
Note Omitting tags is unfamiliar to web developers. It needs time to be established as a guideline.

The HTML <title> Element

The <title> element defines the title of the document.

The <title> element is required in all HTML/XHTML documents.

The <title> element:

  • defines a title in the browser tab
  • provides a title for the page when it is added to favorites
  • displays a title for the page in search engine results

A simplified HTML document:

Example

<!DOCTYPE html>
<html>
<title>Page Title</title>

<body>
The content of the document......
</body>

</html>
Try it Yourself »

The HTML <style> Element

The <style> element is used to define style information for an HTML document.

Inside the <style> element you specify how HTML elements should render in a browser:

Example

<style>
body {background-color:yellow;}
p {color:blue;}
</style>
Try it Yourself »

The HTML <link> Element

The <link> element defines the page relationship to an external resource.

The <link> element is most often used to link to style sheets:

Example

<link rel="stylesheet" href="mystyle.css">
Try it Yourself »

The HTML <meta> Element

The <meta> element is used to specify page description, keywords, author, and other metadata.

Metadata is used by browsers (how to display content), by search engines (keywords), and other web services.

Define keywords for search engines:

<meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript">

Define a description of your web page:

<meta name="description" content="Free Web tutorials on HTML and CSS">

Define the character set used:

<meta charset="UTF-8">

Define the author of a page:

<meta name="author" content="Hege Refsnes">

Refresh document every 30 seconds:

<meta http-equiv="refresh" content="30">

Example of <meta> tags:

Example

<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta name="author" content="Hege Refsnes">
<meta charset="UTF-8">
Try it Yourself »

The HTML <script> Element

The <script> element is used to define client-side JavaScripts.

The script below writes Hello JavaScript! into an HTML element with id="demo":

Example

<script>
function myFunction {
    document.getElementById("demo").innerHTML = "Hello JavaScript!";
}
</script>
Try it Yourself »
Note To learn all about JavaScript, visit our JavaScript Tutorial!

The HTML <base> Element

The <base> element specifies the base URL and base target for all relative URLs in a page:

Example

<base href="https://www.noidatut.com/images/" target="_blank">
Try it Yourself »