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.

Test it Live

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 Name Description
1 accesskey Use to include a key to access the element. The value for this can be any string.
2 class used 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.
3 contenteditable Used to set whether the content element is editable or not. This contains boolean value true/false.
4 contextmenu used to specify the context menu for the element. The value for this is the ID of the menu.
5 dir used to specify the direction of the text. The value for this are from ltr(left to right), rtl(right to left) and auto
6 draggable used to specify whether the user is allowed to drag the element or not. the value for this can be true, false and auto.
7 dropzone Used to specify the element when dragged and drop to somewhere else. The value for this copy, move, link, any string.
8 hidden Use to specify that the element is not yet or no longer relevant. The value for this is hidden.
9 id used to specify the identifier for the element. This can be use for css and javascript.
10 inert Used to show side content for the HTML pages.
11 lang Used to specify the language.
12 spellcheck used to specify whether the element have spelling check or not.
13 style Used to define the styling for the element. The value for this are the css codes we use in stylesheets.
14 tabindex used to define the tabbing order of the element. The value for this can be any integer value like 1,2..
15 title used to define the title of the element.
16 translate Used to define whether the element is translated or not. The value for this can be empty string, true/false.

People also like to read

ULTIMATE TOOLKIT Free eBook

Get FREE Access to Toolkit and Resources that we are using in Tutorialdeep that Every Professional Should Have! in one handy PDF.

Download Link Will be Send to Your Email id