Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App

HTML Global Attributes

Last Updated : 18 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

HTML attributes provide additional information about an element and define its properties. Global attributes are special types of attributes that can be used with any HTML element, offering common functionality to enhance behavior and presentation.

  • Global attributes can be applied to any HTML element, such as <div>, <p>, <img>, and more.
  • They control various aspects like styling, identification, accessibility, and interaction, improving web page design and functionality.
  • Common global attributes include id, class, style, title, and lang.

1. accesskey

The accesskey attribute defines a keyboard shortcut to activate/focus an element.

HTML
<html> <body>     <button accesskey="s">Save</button> </body> </html> 
  • The button can be activated by pressing Alt + S on Windows or Option + S on macOS.
  • This provides a quick way for users to interact with the button without using a mouse.

2. autofocus

The autofocus attribute automatically focuses an element when the page loads.

HTML
<html> <body>     <input type="text" placeholder="Type here..." autofocus /> </body> </html> 
  • The input field receives focus automatically when the page is loaded.
  • Users can start typing immediately without needing to click on the input field.

3. lang

The lang attribute specifies the language of the element's content.

HTML
<html> <body>     <p lang="es">Hola, Mundo!</p> </body> </html> 
  • The paragraph text is in Spanish (es).
  • This helps search engines and screen readers recognize the language of the content, improving accessibility and SEO.

4. class

The class attribute assigns one or more class names to an element, enabling CSS styling or JavaScript manipulation.

HTML
<html> <head>     <style>         .highlight {             color: red;             font-weight: bold;         }     </style> </head> <body>     <p class="highlight">This is a highlighted text.</p> </body> </html> 
  • The paragraph text is styled with a red color and bold font using the highlight class.
  • The class attribute links the HTML element to the CSS rule, making it easy to apply consistent styling.

List of Global Attributes:

Global Attributes

Description

accesskeyIt is the keyboard shortcuts to activate/focus specific elements.
autocapitalizeAutomatically capitalizes text entered by the user.
autofocus: Specifies that an element should get focus when the page loads.
classIt specifies one or more class names for an HTML element.
contenteditableIndicates whether the content of an element can be edited.
contextmenuSpecifies a custom context menu for an element
data-*It can be used to define our own custom data attributes.
dirIt is used to specify the text direction of the element content.
draggableIt is used to specify whether an element is draggable or not. Links and images are by default draggable.
enterkeyhintIt provides a hint on what label or icon to present on a virtual keyword while pressing keys.
hiddenIt is used to define the visibility of elements. It contains a boolean value. If this attribute is used then browsers will not display elements that have the hidden attribute specified.
idProvides a unique identifier for an element.
inputmodeIt is used mainly to provide a hint to browsers on which virtual keyboard configuration to use when editing this element or its contents.
isSpecifies a custom built-in element.
itemidProvides a unique global identifier for an item.
itempropAdds properties to an item.
itemscopeIt works with item types to ensure that the HTML contained in a block is about a particular item.
itemtypeIt specifies the URL vocabulary which is used to define itemprops.
langIt is used to specify the language of the element content. Some examples of languages are en for English, es for Spanish, etc.
nonceIt is a cryptographic nonce ("number used once")  used by a content security policy to check given fetch allowed to proceed or not.
partIt is a space-separated list of the part names of the element.
slotIt is used to assign a slot in a shadow DOM shadow tree to an element.
spellcheckThe Spell Check feature in HTML is used to detect grammatial or spelling mistakes in the text fields.
styleStyle in HTML are basically rules that describe how a document will be presented in a browser.
tabindexIt is used to specify the tab order of an element. It is used when the tab button is used for navigating.
titleIt is used to define the title of an HTML document, sets the title in the browser toolbar, and provides the title for the web page when it is added to favorites.
translateThe translate attribute in HTML is used to specify whether the content of an element is translated or not.

Best Practices for HTML Global Attributes

  • Use global attributes like id, class, style, title, etc., consistently to enhance the accessibility, functionality, and styling of your HTML elements.
  • Ensure attributes like id are unique within a page to prevent conflicts.
  • For styling and layout, prefer using external or internal CSS rather than inline styles for maintainability.

K

kartik
Improve
Article Tags :
  • Web Technologies
  • HTML
  • HTML Global-Attributes

Similar Reads

    HTML Tutorial
    HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript
    11 min read
    HTML Introduction
    HTML stands for Hyper Text Markup Language, which is the core language used to structure content on the web. It organizes text, images, links, and media using tags and elements that browsers can interpret. As of 2025, over 95% of websites rely on HTML alongside CSS and JavaScript, making it a fundam
    6 min read
    HTML Editors
    An HTML Editor is a software application designed to help users create and modify HTML code. It often includes features like syntax highlighting, tag completion, and error detection, which facilitate the coding process. There are two main types of HTML editors: Text-Based Editors - Allow direct codi
    5 min read
    HTML Basics
    HTML (HyperText Markup Language) is the standard markup language used to create and structure web pages. It defines the layout of a webpage using elements and tags, allowing for the display of text, images, links, and multimedia content. As the foundation of nearly all websites, HTML is used in over
    6 min read
    HTML Comments
    HTML comments are used to add notes or explanations in the HTML code that are not displayed by the browser.They are useful for documenting the code, making it easier to understand and maintain.To add a comment, use the syntax <!-- your comment here -->. HTML<!-- This is a comment and will n
    4 min read
    HTML Elements
    An HTML Element consists of a start tag, content, and an end tag, which together define the element's structure and functionality. Elements are the basic building blocks of a webpage and can represent different types of content, such as text, links, images, or headings.For example, the <p> ele
    5 min read
    HTML Attributes
    HTML Attributes are special words used within the opening tag of an HTML element. They provide additional information about HTML elements. HTML attributes are used to configure and adjust the element's behavior, appearance, or functionality in a variety of ways. Each attribute has a name and a value
    8 min read
    HTML Headings
    HTML headings are used to define the titles and subtitles of sections on a webpage. They help organize the content and create a structure that is easy to navigate.Proper use of headings enhances readability by organizing content into clear sections.Search engines utilize headings to understand page
    4 min read
    HTML Paragraphs
    A paragraph in HTML is simply a block of text enclosed within the <p> tag. The <p> tag helps divide content into manageable, readable sections. It’s the go-to element for wrapping text in a web page that is meant to be displayed as a distinct paragraph.Syntax:<p> Some Content...
    5 min read
    HTML Text Formatting
    HTML text formatting refers to the use of specific HTML tags to modify the appearance and structure of text on a webpage. It allows you to style text in different ways, such as making it bold, italic, underlined, highlighted, or struck-through. Table of ContentCategories of HTML Text FormattingLogic
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences