Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

HTML Tutorial

HTML HOME HTML Introduction HTML Editors HTML Basic HTML Elements HTML Attributes HTML Headings HTML Paragraphs HTML Styles HTML Project I HTML Formatting HTML Quotations HTML Comments HTML Colors HTML CSS HTML Project II HTML Links HTML Images HTML Favicon HTML Page Title HTML Tables HTML Lists HTML Project III HTML Block & Inline HTML Div HTML Classes HTML Id HTML Project IV HTML Global Attributes HTML Buttons HTML Iframes HTML JavaScript HTML File Paths HTML Head HTML Layout HTML Responsive HTML Project V HTML Computercode HTML Semantics HTML Project VI HTML Dialog HTML Details HTML Style Guide HTML Entities HTML Symbols HTML Emojis HTML Character Sets HTML Languages HTML URL Encoding HTML Performance HTML SEO

HTML Forms

HTML Forms HTML Form Attributes HTML Form Elements HTML Input Types HTML Input Attributes Input Form Attributes HTML Form Validation HTML Progress and Meter HTML Project VII

HTML Graphics

HTML Canvas HTML SVG

HTML Media

HTML Media HTML Video HTML Audio HTML YouTube HTML Project VIII

Web Accessibility

Web Accessibility ARIA Attributes Keyboard Focus and tabindex Landmarks Skip Links Color Contrast

Web APIs

Web APIs Geolocation API Drag and Drop API Popover API Web Storage API Web Workers API Server-Sent Events API

HTML Cert

HTML Certificate

HTML Examples

HTML Examples HTML Videos HTML Editor HTML Quiz HTML Exercises HTML Challenges HTML Projects HTML Website HTML Syllabus HTML Study Plan HTML Interview Prep HTML Summary

HTML References

HTML Tag List HTML Attributes HTML Global Attributes HTML Browser Support HTML Event Attributes HTML Colors HTML Canvas HTML Audio/Video HTML Doctypes HTML Character Sets HTML URL Encode HTML Language Codes HTML Country Codes HTTP Status Codes HTTP Request Methods PX to EM Converter Keyboard Shortcuts

HTML Global Attributes


Share

What are Global Attributes?

Most attributes only work on some elements, like href works on <a>, and src works on <img>.

Global attributes are different, they can be used on any HTML element.

You already know some of the global attributes:

  • class and id, from the Classes and Id chapters
  • style, title, and lang, from the Attributes chapter

This chapter shows some other useful global attributes.


The hidden Attribute

The hidden attribute hides an element.

The element is still in the HTML source code, but the browser does not show it:

Example

<p>This paragraph is visible.</p>
<p hidden>This paragraph is hidden.</p>
<p>This paragraph is also visible.</p>
Try it Yourself »

This can be useful for content that you show later with JavaScript, like an answer to a question.

Note: Never use hidden for secret information.



The data-* Attributes

The data-* attributes let you store your own information on an element.

The name must start with data-, and the rest of the name is up to you, like data-color or data-price.

The browser does not show the value, but JavaScript can read it with the dataset property:

Example

<ul>
  <li data-color="red" onclick="showColor(this)">Apple</li>
  <li data-color="yellow" onclick="showColor(this)">Banana</li>
  <li data-color="orange" onclick="showColor(this)">Orange</li>
</ul>

<p id="result"></p>

<script>
function showColor(fruit) {
  document.getElementById("result").innerHTML = fruit.innerHTML + " is " + fruit.dataset.color + ".";
}
</script>
Try it Yourself »

If you click Banana, the page shows:

Banana is yellow.

Tip: data-color becomes dataset.color in JavaScript. You will learn more about JavaScript in a later chapter.


The contenteditable Attribute

The contenteditable attribute lets the user change the text of an element, right in the page:

Example

<p contenteditable="true">Click here and change this text.</p>
Try it Yourself »

Note: The changes only live in the browser, and are gone when the user reloads the page (unless you save them with JavaScript).


The spellcheck Attribute

The spellcheck attribute turns the spelling check on or off for text the user types:

Example

<textarea spellcheck="true">Spellcheck is on</textarea>

<textarea spellcheck="false">Spellcheck is off</textarea>
Try it Yourself »

Tip: You can turn spellcheck off for fields where the words are not normal text, like usernames or code.


The translate Attribute

Translation tools, like the ones built into browsers, can translate a whole web page into another language.

The translate attribute is used to tell browsers which text to NOT translate:

Example

<p>Use the <code translate="no">print()</code> function to show text.</p>

Use it for names, brands, and code that must not change.


The dir Attribute

Some languages, like Arabic and Hebrew, are written from right to left.

The dir attribute sets the direction of the text.

The values are ltr (left to right), rtl (right to left), and auto (the browser decides):

Example

<p>This text goes from left to right.</p>

<p dir="rtl">This text goes from right to left!</p>
Try it Yourself »

In the example above, the second paragraph moves to the right side of the page.

The exclamation mark also moves to the left end of the sentence, because that is where a right to left sentence ends.


More Global Attributes

Some global attributes are explained in other chapters:

Attribute What it does Learn more
tabindex Sets the order in which elements get keyboard focus Keyboard Focus
draggable Lets the user drag an element with the mouse Drag and Drop API
popover Turns an element into a popover Popover API
inert Makes an element and its content impossible to click or focus inert reference

Summary

  • Global attributes work on any HTML element
  • hidden hides an element
  • data-* stores your own information, and JavaScript reads it with dataset
  • contenteditable lets the user change the text
  • spellcheck turns the spelling check on or off
  • translate="no" stops translation tools from changing the text
  • dir sets the text direction

For a complete list of all global attributes, visit our HTML Global Attributes Reference.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.