--- url: "https://web.dev/learn/html/attributes" titulek: "Attributes | web.dev" h1: "Attributes Stay organized with collections Save and categorize content based on your preferences." popis: "Learn about the different global attributes along with attributes specific to particular HTML elements." jazyk: "en" kanonicka: "https://web.dev/learn/html/attributes" drobecky: ["web.dev", "Resources", "HTML"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 03:30:45" znaku: 24335 slov: 3548 kodovani: "iso-8859-2" sha256: "7873df6d36f1edc55ed9917d895d9a1908c135afcc678cd2e829c11d66d07cdc" --- Attributes Stay organized with collections Save and categorize content based on your preferences. Attributes were briefly discussed in [Overview of HTML](/learn/html/overview#attributes). It's time for a deep dive. Attributes are what make HTML so powerful. Attributes are space-separated names and name/value pairs appearing in the opening tag, providing information about and functionality for the element. Attributes define the behavior, linkages, and functionality of elements. Some attributes are global, meaning they can appear within any element's opening tag. Other attributes apply to several elements but not all, while other attributes are element-specific, relevant only to a single element. In HTML, all attributes except boolean, and to some extent enumerated attributes, require a value. If an attribute value includes a space or special characters, the value must be quoted. For this reason and improved legibility, quotations are always recommended. While HTML isn't case-sensitive, some attribute values are. Values that are part of the HTML specification are case-insensitive. Strings values that are defined, such as class and ID names, are case-sensitive. If an attribute value is case-sensitive in HTML, it's case-sensitive when used as an [attribute selector](https://developer.mozilla.org/docs/Web/CSS/Attribute_selectors) in CSS and in JavaScript; otherwise, it's not. `
HAL and EVE could teach a fan to blow hot air.` You can use `getAttribute()` using the full attribute name, or you can take advantage of the simpler [`dataset`](https://developer.mozilla.org/docs/Web/API/HTMLElement/dataset) property. `el.dataset["machineLearning"]; // workshop e.dataset.machineLearning; // workshop` The `dataset` property returns a `DOMStringMap` object of each element's `data-` attributes. There are several custom attributes on the `
`. The dataset property means you don't need to know what those custom attributes are in order to access their names and values: `for (let key in el.dataset) { customObject[key] = el.dataset[key]; }` The attributes in this article are global, meaning they can be applied to any HTML element (though they don't all have an impact on those elements). Up next, we take a look at the two attributes from the intro image that we didn't addressâ`target` and `href`âand several other element-specific attributes as we take a deeper look into links. Check your understanding Test your knowledge of attributes. An `id` should be unique in the document. False Try again. True Correct! Select the correctly formed custom attribute. `data-birthday` Correct `birthday` Try again. `data:birthday` Try again [Previous arrow_back Headings and sections](/learn/html/headings-and-sections) [Next Text basics arrow_forward](/learn/html/text-basics) Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2022-12-08 UTC.