MyInternships.in

HTML Attributes

HTML Global Attributes

Global attributes are attributes that can be applied to any HTML element to set common properties like identity, styling, language and interactivity. They give you a consistent toolkit across all your markup.


What Are Global Attributes?

Global attributes are a group of attributes that are valid on every HTML element, regardless of the element's specific purpose. They handle universal concerns like identification, styling, language and interactivity, so you can use the same attribute names consistently across your markup.

Syntax

ℹ️

Global attributes use the usual name="value" form and can appear on any element, for example <div id="hero" class="banner" lang="en">.

The basic pattern
Example
<div id="hero" class="banner" title="Welcome">Content</div>

Example

Run this example to see several global attributes on real, visible elements — hover for the title tooltip and click into the editable box.

Global attributes on visible elements
Example
<!DOCTYPE html>
<html>
  <body>
    <div id="hero" class="banner" lang="en"
         title="Hover to see this tooltip"
         style="padding: 12px; background: #eef">
      Welcome to MyInternships.in
    </div>

    <p contenteditable="true" style="border: 1px solid #999; padding: 8px">
      This paragraph is editable — click and type inside it.
    </p>

    <p dir="rtl">This paragraph flows right-to-left because of dir="rtl".</p>

    <button data-job-id="42" onclick="alert('Job id: ' + this.dataset.jobId)">
      Show data-* value
    </button>
  </body>
</html>

Common Global Attributes

AttributeDescription
idA document-unique identifier for the element
classSpace-separated list of class names for CSS and scripting
styleInline CSS declarations applied to the element
titleAdvisory information shown as a tooltip on hover
langLanguage of the element's content, e.g. en, hi, mr
dirText direction: ltr, rtl or auto
hiddenBoolean attribute that hides the element from rendering
tabindexControls keyboard tab order and focusability
contenteditableWhether the element's content can be edited by the user
draggableWhether the element can be dragged (true or false)
data-*Custom author-defined attributes for storing extra data
accesskeyKeyboard shortcut hint to focus or activate the element
spellcheckWhether the browser should check spelling and grammar
💡

Use data-* attributes to attach custom information to elements for JavaScript, e.g. data-job-id="42". Access them in script via the element's dataset property (element.dataset.jobId).

Key Takeaways

  • Global attributes work on every HTML element.
  • id and class are the most-used, connecting HTML to CSS and JavaScript.
  • lang and dir set language and text direction for accessibility.
  • contenteditable, draggable and tabindex add interactivity.
  • data-* attributes store custom data read via element.dataset.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships