HTML <head> tagS2C Home   « 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 which 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 must always come first in any HTML document --> 
<html  lang="en">
<!-- Everything 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 the 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>

Required Attributes

title - specifies extra information about the content.


<head title="information about the content">Head elements here</footer>

Optional Attributes

profile - specifies the URL location(s) of a meta data profile.


<head profile="aURL">Head elements here</head>

Global Attributes

Common

class - specifies a classname for the element allowing you to apply the style of the predefined class to the content.


<head class="classname">Head elements here</footer>

id - specifies a unique id for the element allowing you to apply the style of the predefined id to the content.


<head id="idname">Head elements here</footer>

style - specifies an inline style for the element allowing you to apply the style to the content.


<head style="color:red;text-align:left">Head elements here</footer>

Keyboard

accesskey - specifies a keyboard shortcut to associate with the element.


<head accesskey="aKeyValue">Head elements here</head>

tabindex - specifies a tab order for the element.


<head tabindex="someNumber">Head elements here</head>

Language

dir - specifies the directional flow of the content.


<head dir="ltr">Head elements here</head>   <!-- The text will flow from left to right -->
<head dir="rtl">Head elements here</head>   <!-- The text will flow from right to left -->

lang - specifies a language code for the content of the element.


<head lang="en">Head elements here</head>

spellcheck - specifies whether the element is to have its spelling checked.


<!-- Valid values are true and  false - default is inherited/browser specific. -->
<head spellcheck="true">Head elements here</head>

translate - specifies whether the content of the element can be translated.


<!-- Valid values are yes and  no - default is yes. -->
<head translate="no">Head elements here</head> 

Miscellaneous

contenteditable - specifies whether the content of the element is editable.


<!-- Valid values are true and  false - default is inherited. -->
<head contenteditable="false">Head elements here</head> 

draggable - specifies whether the the element is draggable.

Only text selections, images, and links can be dragged.


<!-- Valid values are true and  false - default is browser specific. -->
<head draggable="true">Head elements here</head>

hidden - specifies whether the element is not yet, or no longer, relevant.


<!-- Valid values are an empty string or hidden -->
<head hidden>Head elements here</head> 
<head hidden="hidden">Head elements here</head> 

Event Attributes

Document

onabort - The JavaScript code to be run on abort.


<head onabort="go()">Head elements here</head>   <!-- Executes the go() function -->

onerror - The JavaScript code to be run when an error occurs when the file is being loaded.


<head onerror="go()">Head elements here</head>   <!-- Executes the go() function -->

onload - The JavaScript code to be run when the document is loaded.


<head onload="go()">Head elements here</head>   <!-- Executes the go() function -->

onresize - The JavaScript code to be run when the browser window is resized.


<head onresize="go()">Head elements here</head>   <!-- Executes the go() function -->

onscroll - The JavaScript code to be run when the scrollbar of an element is being scrolled.


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

onunload - The JavaScript code to be run once a page has unloaded or the browser window has been closed.


<head onunload="go()">Head elements here</head>   <!-- Executes the go() function -->

Document Element

oncopy - The JavaScript code to be run when the user copies the content of an element.


<head oncopy="go()">Head elements here</head>   <!-- Executes the go() function -->

oncut - The JavaScript code to be run when the user cuts the content of an element.


<head oncut="go()">Head elements here</head>   <!-- Executes the go() function -->

onpaste - The JavaScript code to be run when the user pastes some content into an element.


<head onpaste="go()">Head elements here</head>   <!-- Executes the go() function -->

Drag and Drop

ondrag - The JavaScript code to be run when an element is dragged.


<head ondrag="go()">Head elements here</head>   <!-- Executes the go() function -->

ondragend - The JavaScript code to be run when an element has stopped being dragged.


<head ondragend="go()">Head elements here</head>   <!-- Executes the go() function -->

ondragenter - The JavaScript code to be run when an element has been dragged to a valid drop target.


<head ondragenter="go()">Head elements here</head>   <!-- Executes the go() function -->

ondragleave - The JavaScript code to be run when an element leaves a valid drop target.


<head ondragleave="go()">Head elements here</head>   <!-- Executes the go() function -->

ondragover - The JavaScript code to be run when an element is being dragged over a valid drop target.


<head ondragover="go()">Head elements here</head>   <!-- Executes the go() function -->

ondragstart - The JavaScript code to be run at the start of a drag operation.


<head ondragstart="go()">Head elements here</head>   <!-- Executes the go() function -->

ondrop - The JavaScript code to be run when dragged element is being dropped.


<head ondrop="go()">Head elements here</head>   <!-- Executes the go() function -->

Form

onblur - The JavaScript code to be run on abort.


<head onblur="go()">Head elements here</head>   <!-- Executes the go() function -->

onchange - The JavaScript code to be run when object changed and attempt to leave field.


<head onchange="go()">Head elements here</head>   <!-- Executes the go() function -->

oncontextmenu - The JavaScript code to be run when a context menu is triggered.


<head oncontextmenu="go()">Head elements here</head>   <!-- Executes the go() function -->

onfocus - The JavaScript code to be run when the element gets focus.


<head onfocus="go()">Head elements here</head>   <!-- Executes the go() function -->

oninput - The JavaScript code to be run when an element gets user input.


<head oninput="go()">Head elements here</head>   <!-- Executes the go() function -->

oninvalid - The JavaScript code to be run when an element is invalid.


<head oninvalid="go()">Head elements here</head>   <!-- Executes the go() function -->

onreset - The JavaScript code to be run when the reset button of a form is clicked.


<head onreset="go()">Head elements here</head>   <!-- Executes the go() function -->

onselect - The JavaScript code to be run when some or all of the contents of an object are selected.


<head onselect="go()">Head elements here</head>   <!-- Executes the go() function -->

onsubmit - The JavaScript code to be run when a form is submitted.


<head onsubmit="go()">Head elements here</head>   <!-- Executes the go() function -->

Keyboard

onkeydown - The JavaScript code to be run when an element is in focus and keyboard key is pressed.


<head onkeydown="go()">Head elements here</head>   <!-- Executes the go() function -->

onkeypress - The JavaScript code to be run when an element is in focus and keyboard key is pressed down and released.


<head onkeypress="go()">Head elements here</head>   <!-- Executes the go() function -->

onkeyup - The JavaScript code to be run when an element is in focus and keyboard key is released.


<head onkeyup="go()">Head elements here</head>   <!-- Executes the go() function -->

Media

oncanplay - The JavaScript code to be run when a file has buffered enough so it is ready to start playing.


<head oncanplay="go()">Head elements here</head>   <!-- Executes the go() function -->

oncanplaythrough - The JavaScript code to be run when a file can be played all the way to the end without further need of buffering.


<head oncanplaythrough="go()">Head elements here</head>   <!-- Executes the go() function -->

oncuechange - The JavaScript code to be run when the cue changes when using the track element.


<head oncuechange="go()">Head elements here</head>   <!-- Executes the go() function -->

ondurationchange - The JavaScript code to be run when the length of the media is changed.


<head ondurationchange="go()">Head elements here</head>   <!-- Executes the go() function -->

onemptied - The JavaScript code to be run when a media resource element suddenly becomes empty, usually due to an error.


<head onemptied="go()">Head elements here</head>   <!-- Executes the go() function -->

onended - The JavaScript code to be run when the media has reach the end.


<head onended="go()">Head elements here</head>   <!-- Executes the go() function -->

onloadeddata - The JavaScript code to be run when media data is loaded and playback can start.


<head onloadeddata="go()">Head elements here</head>   <!-- Executes the go() function -->

onloadedmetadata - The JavaScript code to be run when metadata has been loaded.


<head onloadedmetadata="go()">Head elements here</head>   <!-- Executes the go() function -->

onloadstart - The JavaScript code to be run when the media resource has started loading.


<head onloadstart="go()">Head elements here</head>   <!-- Executes the go() function -->

onpause - The JavaScript code to be run when the media resource has been paused.


<head onpause="go()">Head elements here</head>   <!-- Executes the go() function -->

onplay - The JavaScript code to be run when the media resource starts playback.


<head onplay="go()">Head elements here</head>   <!-- Executes the go() function -->

onplaying - The JavaScript code to be run when playback has already begun.


<head onplaying="go()">Head elements here</head>   <!-- Executes the go() function -->

onprogress - The JavaScript code to be run when the browser is fetching the media data.


<head onprogress="go()">Head elements here</head>   <!-- Executes the go() function -->

onratechange - The JavaScript code to be run when the playback rate changes.


<head onratechange="go()">Head elements here</head>   <!-- Executes the go() function -->

onseeked - The JavaScript code to be run when the seeking attribute is set to false indicating that seeking has finished.


<head onseeked="go()">Head elements here</head>   <!-- Executes the go() function -->

onseeking - The JavaScript code to be run hen the seeking attribute is set to true indicating that seeking is currently active.


<head onseeking="go()">Head elements here</head>   <!-- Executes the go() function -->

onstalled - The JavaScript code to be run when the browser is unable to continue fetching media data.


<head onstalled="go()">Head elements here</head>   <!-- Executes the go() function -->

onsuspend - The JavaScript code to be run when media data has stopped before being completely loaded.


<head onsuspend="go()">Head elements here</head>   <!-- Executes the go() function -->

ontimeupdate - The JavaScript code to be run when the media resources current playback position has changed.


<head ontimeupdate="go()">Head elements here</head>   <!-- Executes the go() function -->

onvolumechange - The JavaScript code to be run when the volume has changed or been muted.


<head onvolumechange="go()">Head elements here</head>   <!-- Executes the go() function -->

onwaiting - The JavaScript code to be run when the media resource has paused but is expected to resume.


<head onwaiting="go()">Head elements here</head>   <!-- Executes the go() function -->

Mouse

onclick - The JavaScript code to be run when a mouse is clicked on the element.


<head onclick="go()">Head elements here</head>   <!-- Executes the go() function -->

ondblclick - The JavaScript code to be run when a mouse is double clicked on the element.


<head ondblclick="go()">Head elements here</head>   <!-- Executes the go() function -->

onmousedown - The JavaScript code to be run when the mouse button is pressed down while the cursor is over the element.


<head onmousedown="go()">Head elements here</head>   <!-- Executes the go() function -->

onmousemove - The JavaScript code to be run when the mouse button is moved.


<head onmousemove="go()">Head elements here</head>   <!-- Executes the go() function -->

onmouseout - The JavaScript code to be run when the mouse cursor moves off an element.


<head onmouseout="go()">Head elements here</head>   <!-- Executes the go() function -->

onmouseover - The JavaScript code to be run when the mouse cursor moves over an element.


<head onmouseover="go()">Head elements here</head>   <!-- Executes the go() function -->

onmouseup - The JavaScript code to be run when the mouse button is released while the cursor is over the element.


<head onmouseup="go()">Head elements here</head>   <!-- Executes the go() function -->

onwheel - The JavaScript code to be run when the mouse wheel rolls up or down over an element.


<head onwheel="go()">Head elements here</head>   <!-- Executes the go() function -->

Window

NONE

go to home page Homepage go to top of page Top