HTML <meta> tagS2C Home   « HTML <meta> tag

Definition

The <meta> tag is a self closing tag used for generic metadata information within a HTML document.

The <meta> tag must reside within the <head></head> element.

Metadata can be used to specify such things as a character set for the document, a descripton for the document, keywords relating to the content of the document, an author of the document, to refresh or redirect the page and viewport settings.

Example


<!DOCTYPE html>   <!-- The DOCTYPE declaration always comes first in a HTML document --> 
<html  lang="en">
<head>
  <title>A Title which will appear in the Windows title bar.</title>
  <!-- Some suggested meta types follow -->
  <meta charset="utf-8">
  <meta name="description" content="In this HTML tutorial reference">
  <meta name="keywords" content="HTML,CSS,JavaScript,jQuery">
  <meta name="viewport" content="width=device-width">
</head>
<body>
</body>
</html>

Attributes

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


<meta> Specific Attributes
Attribute Value Description Example
charsetcharacter-setDeclares the document's character encoding.

<meta charset="utf-8">
contentvalueSpecifies the value associated with the http-equiv or name attribute.

<meta name="Description" 
      content="some text">
http-equivUsed to describe an equivalent HTTP-Header and the value we wish to use for it.

Use the http-equiv attribute or the name attribute, not both.

<!-- Define the MIME type for the content -->
<meta http-equiv="content-type" 
      content="text/html; 
      charset="UTF-8">
<!-- Define a pages refresh rate (avoid this!) -->
<meta http-equiv="refresh" 
      content="20">
content-securityEnforces a Content Security Policy on a Document.
content-typeAn alternative form of setting the charset attribute. When used in this context the attribute value must be an ASCII case-insensitive match for the string "utf-8".
default-styleSets the name of default style spreadsheet.
refreshRefresh the Document.
namenameUsed to describe the name of the metadata in the content attribute and can be any value you choose.

Use the http-equiv attribute or the name attribute, not both.

<!-- Define a description for the content -->
<meta name="description" 
      content="some text here">

<!-- Define keywords used in the document -->
<meta name="keywords" 
      content="HTML,CSS">

<!-- Define a viewport for the document -->
<meta name="viewport"
      content="width=device-width">
<meta> 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.

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

<meta id="name">
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

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

<meta title="Content info">
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<meta accesskey="a">
tabindexSpecifies a tab order for the element.

<meta tabindex="1">
Language
dirSpecifies the directional flow of the content.

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

<meta lang="en">
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. -->
<meta spellcheck="true"> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 <!-- Executes go() function -->
<meta oncanplay="go()">
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 -->
<meta oncanplaythrough="go()">
oncuechangeThe script to be run when the cue changes when using the track element.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 <!-- Executes go() function -->
<meta onscroll="go()"> 
Window - NONE

Relevant HTML Tutorials

HTML Intermediate - Metadata