View video tutorial

HTML Attributes

HTML

Attributes add additional properties and behavior to HTML 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.

The beginning tag is the place where attributes are placed.

Attributes are name-value pairs. So the value must be assigned to the attribute name.

Global attributes

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

Name Description
accesskey The HTML accesskey attribute defines a keyboard shortcut for activating or focusing an element
class Assigning one or more class names to an HTML element
contenteditable The HTML contenteditable attribute specifies whether the content of an element is editable by the user.
dir The dir attribute is used to specify the text direction of the element's content.
draggable This attribute is used to specify whether an element can be dragged by the user.
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 This spellcheck attribute specifies whether the spelling and grammar of an element should be checked by the browser.
style Specifies zero or more CSS declarations applicable to the element.
tabindex Allows developers to control the focus order of elements on a webpage.
title It provides information about the element, usually displayed as a tooltip, when the user places the mouse cursor over 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="https://w3context.com">Welcome to w3context</a> 

The target Attribute

 <a href="https://w3context.com" 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> 

Example

<!DOCTYPE html>
<html>
<head>
    <title>HTML Attribute Example</title>
</head>
<body>
    <h2>HTML Attribute Example</h2>
    <p title="Title goes here.">Title is a global attribute.</p>
</body>
</html>
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