View video tutorial

HTML Attributes


Attributes add additional properties and behaviors to the elements.

HTML Atrributes

Attributes add extra properties to an element.

Elements can have one or more attributes.

Some attributes are optional and some are mandatory for an element.

Beginning tag is the place to place attributes.

Attributes are name value pair. So the value must be assign to the attribute name.

Global attributes

This section describes attributes that are common to all HTML language elements

Name Description
accesskey list of key labels
class set of space-separated tokens/td>
contenteditable Specifies whether the contents of the element are editable.
contextmenu The value of the id attribute on the menu.
dir Specifies the text direction of the element.
draggable Specifies whether the material can be drag.
hidden Specifies that the element is hidden.
id A unique identifier for the element.
lang Specifies the primary language for the contents of the element.
spellcheck Specifies whether the element represents an element whose content is subject to spell checking and grammar verification.
style Specifies zero or more CSS declarations applicable to the element.
tabindex Specifies whether the element represents an element that is focusable and in relative order.
title Instructive information related to the element.

Learning with HTML Editor "Try it Now"

You can edit the HTML code and view the result using online editor.

The src Attribute

 <img src="puppy.jpg"> 

The width and height Attributes

 <img src="puppy.jpg" width="250" height="300">

The alt Attribute

 <img src="puppy.jpg" width="250" height="300" alt="The nice puppy">

The href Attribute

 <a href="">Welcome to w3context</a> 

The target Attribute

 <a href="" target="_blank">Welcome to w3context</a> 

The style Attribute

 <h3 style="color:red;">This is a paragraph.</h3> 

The title Attribute

<p title="Title goes here.">Title is a global attribute.</p> 


<!DOCTYPE html>
    <title>HTML Attribute Example</title>
    <h2>HTML Attribute Example</h2>
    <p title="Title goes here.">Title is a global attribute.</p>
Try it Now »

Click on the "See output" button to see how it works.

Note: For a complete list of all available HTML attribute list, visit HTML Attribute List