HTML Attributes
HTML Living Standard
An attribute in an opening tag gives an HTML element extra information or changes how it works. Standard attributes are the ones defined by the HTML Standard. These include global attributes and attributes that apply to specific elements.
On this page
How Attributes Work
Global attributes such as id and class can be used on any HTML element. Use a unique id for each element you want to identify and reuse a class to style multiple elements. Other attributes apply to specific elements. On an <a> element, href sets the link destination. On an <img> element, src sets the image address and alt provides a text alternative.
How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How Attributes Work</title>
<style>
.highlight { color: teal; }
h2:target { outline: 2px solid teal; }
</style>
</head>
<body>
<a class="highlight" href="#schedule">View schedule</a>
<h2 id="schedule" class="highlight">Schedule</h2>
<p>Classes begin at 10:00 AM.</p>
</body>
</html>
What to expect The link and heading are teal because both use class="highlight". Click View schedule to jump to the heading whose id matches the link’s href.