HTML5 Reference

HTML <head> tag

Definition

The <head> tag denotes the document head element of a HTML document.

The <head> tag must come directly after the <html> opening tag and must precede the <body> opening tag.

The <head> element can contain the following tags: <base>, <link>, <meta>, <noscript>, <script>, <style> and <title>.

The <title> tag is the only required tag of the <head> element.

Example


<!DOCTYPE html>   <!-- The DOCTYPE declaration always comes first in a HTML document --> 
<html lang="en">
<!-- Everything else goes between the start and end HTML tags. --> 
<head>
<!-- The header contains meta information pertaining to the HTML document as well as a title and other stuff we will discuss in HTML Intermediate/Advanced lessons. External files such as CSS stylesheets and JavaScript files are also imported in the header section of our HTML file. -->
  <title>A Title which will appear in the Windows title bar.</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <noscript>Text only visible when JavaScript is turned off or unavailable.</noscript>
  <base href="https://server2client.com/">
  <link href="../global.css" rel="stylesheet" type="text/css">
  <!-- For efficiency imported JavaScript files should go just before closing body tag -->
  <script src="../js/jquery.js" type="text/javascript"></script>
  <script type="text/javascript">Javascript in here</script>
  <style type="text/css">CSS in here</style>
</head>
<body>
<!-- The content of the web page appears in the body section. -->
</body>
<!-- We complete the HTML file with the closing HTML tag. -->
</html>

Attributes

The following attributes can be used with the <head> tag.


<head> Specific Attributes
Attribute Value Description Example
There are no required or optional attributes specific to the <head> tag.
<head> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<head class="name">Head elements</head>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<head id="name">Head elements</head>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<head style="color:red;">Head elements</head>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<head title="Content info">Head elements</head>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<head accesskey="a">Head elements</head>
tabindexSpecifies a tab order for the element.

<head tabindex="1">Head elements</head>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<head dir="ltr">Head elements</head>
<!-- The text will flow from right to left -->
<head dir="rtl">Head elements</head>
langSpecifies a language code for the content of the element.

<head lang="en">Head elements</head>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited / browser specific. -->
<head spellcheck="true">Head elements</head> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<head translate="no">Head elements</head> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<head contenteditable="true">Head elements</head> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<head draggable="true">Head elements</head>
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<head hidden>Head elements</head> 
<head hidden="hidden">Head elements</head> 
<head> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<head oncopy="go()">Head elements</head> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<head oncut="go()">Head elements</head>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<head onpaste="go()">Head elements</head>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<head ondrag="go()">Head elements</head>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<head ondragend="go()">Head elements</head>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<head ondragenter="go()">Head elements</head>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<head ondragleave="go()">Head elements</head>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<head ondragover="go()">Head elements</head>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<head ondragstart="go()">Head elements</head>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<head ondrop="go()">Head elements</head>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<head onblur="go()">Head elements</head>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<head onchange="go()">Head elements</head>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<head oncontextmenu="go()">Head elements</head>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<head onfocus="go()">Head elements</head>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<head oninput="go()">Head elements</head>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<head oninvalid="go()">Head elements</head>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<head onreset="go()">Head elements</head>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<head onselect="go()">Head elements</head>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<head onsubmit="go()">Head elements</head>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<head onkeydown="go()">Head elements</head>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<head onkeypress="go()">Head elements</head>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<head onkeyup="go()">Head elements</head>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<head onabort="go()">Head elements</head>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<head oncanplay="go()">Head elements</head>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<head oncanplaythrough="go()">Head elements</head>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<head oncuechange="go()">Head elements</head>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<head ondurationchange="go()">Head elements</head>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<head onemptied="go()">Head elements</head>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<head onended="go()">Head elements</head>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<head onloadeddata="go()">Head elements</head>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<head onloadedmetadata="go()">Head elements</head>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<head onloadstart="go()">Head elements</head>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<head onpause="go()">Head elements</head>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<head onplay="go()">Head elements</head>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<head onplaying="go()">Head elements</head>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<head onprogress="go()">Head elements</head>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<head onratechange="go()">Head elements</head>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<head onseeked="go()">Head elements</head>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<head onseeking="go()">Head elements</head>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<head onstalled="go()">Head elements</head>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<head onsuspend="go()">Head elements</head>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<head ontimeupdate="go()">Head elements</head>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<head onvolumechange="go()">Head elements</head>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<head onwaiting="go()">Head elements</head>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<head onclick="go()">Head elements</head>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<head ondblclick="go()">Head elements</head>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<head onmousedown="go()">Head elements</head>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<head onmousemove="go()">Head elements</head>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<head onmouseout="go()">Head elements</head>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<head onmouseover="go()">Head elements</head>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<head onmouseup="go()">Head elements</head>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<head onwheel="go()">Head elements</head>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<head onscroll="go()">Head elements</head> 
Window - NONE

Relevant HTML Tutorials

HTML Basics - HTML Structure - Document