HTML Attributes: How to Use Attributes in HTML Tags

In this tutorial, learn how to use HTML attributes with the HTML tags. HTML attributes are the words you can place inside the HTML tags. These attributes are included in the HTML opening tag. Each attribute comes with a unique word with its value to specify.

Let us takes an example of the HTML anchor tag. Below is the example showing the anchor tag with href attribute added inside.

The attribute href has some value using the equals to(=) operator. The attribute value comes inside the double quote(” “). However, you can also use the single quote(‘ ‘) to add the value of the attribute.

You can add the attributes to any HTML elements. The main thing you have to follow is the HTML tag related attributes. You can add only the matching attributes to the tag.

The above anchor tag attribute will not work with the action attribute of HTML form tag.

Global HTML attributes

HTML attributes for HTML tags supports global attributes. These attributes can be used with any tags. Global means for all.

Sr. No.Attribute NameDescription
1accesskeyUse to include a key to access the element. The value for this can be any string.
2classused to include class identifier to html elements. This identifies can be use to get the element give styling and script. The value for this csn be any string.
3contenteditableUsed to set whether the content element is editable or not. This contains boolean value true/false.
4contextmenuused to specify the context menu for the element. The value for this is the ID of the menu.
5dirused to specify the direction of the text. The value for this are from ltr(left to right), rtl(right to left) and auto
6draggableused to specify whether the user is allowed to drag the element or not. the value for this can be true, false and auto.
7dropzoneUsed to specify the element when dragged and drop to somewhere else. The value for this copy, move, link, any string.
8hiddenUse to specify that the element is not yet or no longer relevant. The value for this is hidden.
9idused to specify the identifier for the element. This can be use for css and javascript.
10inertUsed to show side content for the HTML pages.
11langUsed to specify the language.
12spellcheckused to specify whether the element have spelling check or not.
13styleUsed to define the styling for the element. The value for this are the css codes we use in stylesheets.
14tabindexused to define the tabbing order of the element. The value for this can be any integer value like 1,2..
15titleused to define the title of the element.
16translateUsed to define whether the element is translated or not. The value for this can be empty string, true/false.

People also like to read