X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML Head


The HTML <head> Element

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

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

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

The following tags describes meta data: <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>
<head>
<title>Page Title</title>
</head>

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

Try it Yourself »

Note W3Schools 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 and 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 toolbar
  • 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.

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

Define keywords for search engines:

Example

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

Define a description of your web page:

Example

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

 Define the character set used:

Example

<meta charset="UTF-8">

Define the author of a page:

Example

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

Try it Yourself »

Refresh document every 30 seconds:

Example

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


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="http://www.w3schools.com/images/" target="_blank">

Try it Yourself »


HTML head Elements

Tag Description
<head> Defines information about the document
<title> Defines the title of a document
<base> Defines a default address or a default target for all links on a page
<link> Defines the relationship between a document and an external resource
<meta> Defines metadata about an HTML document
<script> Defines a client-side script
<style> Defines style information for a document



Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook