HTML Global Attributes

HTML Global Attributes are the attributes that can be specified on all HTML elements, with some exceptions where these are not relevant.

These cannot be used on elements inside the <head> section, like <base>, <title>, <style>, <script>, etc.,

Here is a list of global attributes.

Attribute Value Description
accesskey keyboard shortcut key Specifies a keyboard shortcut key to activate or focus the element.
class class-name Specifies one or more class names for an element, which can be referred to in CSS or Javascript.
contenteditable true (or) false Specifies whether the content of an element is editable or not.
contextmenu menu-id Specifies a context menu for the element, which is nothing but the menu that appears when the user clicks the mouse right button on the element.
data-* data Specified on elements to store custom data private to the page or application.
dir ltr (or) rtl Specifies text direction for the content in an element.
draggable true (or) false Specifies whether an element is draggable or not.
dropzone copy (or) move (or) link Specifies whether the dragged data is copied, moved, or linked when dropped.
hidden NA Specifies whether the element is not yet, or is no longer, relevant.
id id-name Specifies a unique id for the element.
lang language-code Specifies a language code for the element's content.
spellcheck true (or) false Specifies whether to apply spelling and grammar check on the element's content or not.
style style Specifies inline styles for the element.
tabindex number Specifies the tabbing order of the element.
title text Specifies some extra information about the element, which is displayed as a tooltip upon cursor hover.
translate yes (or) no Specifies whether to translate the element's content or not.

Examples

The below example can explain all these attributes.

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <h1>HTML Global Attributes</h1>    
    <p id="pa" class="para" style="color: red;" title="Main Paragraph">Paragraph text goes here.</p> 

</body>
</html>

Overall

We now know the attributes that can be used on all HTML elements.