HTML5 Attributes

  • An HTML attribute is a modifier of an HTML element.
  • HTML attributes generally appear as name-value pairs, separated by "=", and are written within the start tag of an element, after the element's name.
  • Where tag names the HTML element, attribute is the name of the attribute, set to the provided value.
  • The value may be enclosed in single or double quotes, although values consisting of certain characters can be left unquoted in HTML (but not XHTML).
  • Leaving attribute values unquoted is considered unsafe.

How to use Attributes with Elements

  • Attributes must be in lower case.
  • Attribute value must be in double qoutes("").
  • Attributes is just like key-value pair and written as attribute="value"

  • <tag attribute="value">(content to be modified by the tag)</tag>

  • Common attributes are :
    1. id : Defines a unique id for an element.
    2. class : Refers to a class in style sheet( css).
    3. style : Defines a specific inline style sheet ( css).
    4. title : Defines more information about element.
< element id="Id" class="Class" style="color:red;" title="Java Techies">

HTML5 Event Attributes List

  • Event occur when user come and click on button, or over mouse on any link.
  • Thus you must be create your event handler in java script or vb script.
  • HTML5 give us many event attribute to handle all that event and less code of java script.
  • In HTML5 you can call any other java script function from event attribute.

List of some Event Attribute
onabort oncanplay oncanplay through oncontextmenu ondrag
ondragend ondragenter ondragleave ondragstart ondrop
onduration change onemptied onended onerror onformchange
onforminput oninput oninvalid onloadeddata onloaded metadata
onloadstart onmousewheel onpause onplay onplaying
onprogress onratechange onready statechange onscroll onseeked
onseeking onshow onstalled onsuspend ontimeupdate
onvolume change onwaiting

HTML5 New Form Attributes

HTML5 has several new attributes for <form> and <input>.

New attributes for <form>:
  • autocomplete
  • novalidate
New attributes for <input>:
  • autocomplete
  • autofocus
  • form
  • formaction
  • formenctype
  • formmethod
  • formnovalidate
  • formtarget
  • height and width
  • list
  • min and max
  • multiple
  • pattern (regexp)
  • placeholder
  • required
  • step