HTML5 Reference

HTML <style> tag

Definition

The <style> tag allows us to put style information into our HTML documents and must reside within the <head> element.

Example


<!DOCTYPE html>   <!-- The DOCTYPE declaration always comes first in a HTML document --> 
<html  lang="en">   <!-- Always enter a language for a webpage -->
<head>
  <title>Appears in browser toolbar, favourites and search engime results.</title>
  <style type="text/css">.red {color: red;} </style>
</head>
<body>
  <h2 class="red">Using Inline Styling</h2>
</body>
</html>

Using Inline Styling

Attributes

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


<style> Specific Attributes
Attribute Value Description Example
mediamedia_querySpecifies the device the styles apply to

Defaults to all - other possible values include aural, braille, handheld, projection, print and screen.

style type="text/css" 
      media="print"></style> 
typemedia_typeSpecifies the MIME type of the style sheet.

Must be a valid MIME type

style type="text/css"></style> 
<style> 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.

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

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

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

<style title="Content info">Styling Text</style>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<style accesskey="a">Styling Text</style>
tabindexSpecifies a tab order for the element.

<style tabindex="1">Styling Text</style>
Language
dirSpecifies the directional flow of the content.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 <!-- Executes go() function -->
<style onscroll="go()">Styling Text</style> 
Window - NONE

Relevant HTML Tutorials

HTML Intermediate - Metadata