HTML attributes provide additional information or functionality to HTML elements, modifying their behavior, appearance, or relationships with other elements. They are specified within the opening tag of an element in the format attribute=”value”. HTML5 supports a wide range of attributes, including global attributes (applicable to most elements) and element-specific attributes (unique to certain tags). Listing all attributes and their possible values exhaustively would be extensive, as HTML5 includes hundreds of attributes and values, many context-dependent or tied to specific elements.

1. Global Attributes

Global attributes can be used on any HTML element. They provide universal functionality like styling, identification, or accessibility.

AttributeDescriptionPossible ValuesExample
accesskeyDefines a keyboard shortcut to activate/focus an element.Single character (e.g., “s”, “1”)<button accesskey=”s”>Save</button><br>Press Alt+S (Windows) to activate.
classSpecifies one or more CSS classes for styling.Space-separated class names<ul class=”menu primary”><br>Applies CSS rules for .menu and .primary.
contenteditableMakes an element’s content editable.“true”, “false”<p contenteditable=”true”>Edit me!</p><br>Allows users to modify the paragraph.
data-*Stores custom data for scripting.Any string (e.g., data-id=”123″)<li data-item=”apple”>Apple</li><br>JavaScript can access dataset.item.
dirSets text direction.“ltr”, “rtl”, “auto”<div dir=”rtl”>Arabic text</div><br>Displays text right-to-left.
draggableEnables drag-and-drop functionality.“true”, “false”<li draggable=”true”>Drag me</li><br>Allows dragging with JavaScript.
hiddenHides an element from display.Boolean (present or empty, e.g., hidden or hidden=””)<ul hidden><li>Hidden item</li></ul><br>List is not visible.
idAssigns a unique identifier to an element.Unique string (no spaces)<ul id=”nav”><br>Targets list with CSS (#nav) or JavaScript.
langSpecifies the language of the element’s content.Language code (e.g., “en”, “fr”)<html lang=”en”><br>Indicates English content.
spellcheckEnables/disables spell-checking.“true”, “false”<textarea spellcheck=”true”></textarea><br>Checks spelling in the textarea.
styleApplies inline CSS styles.CSS rules (e.g., “color: blue;”)<li style=”color: red;”>Red item</li><br>Item text is red.
tabindexControls keyboard focus order.Integer (e.g., “0”, “1”, “-1”)<li tabindex=”1″>Focusable</li><br>Makes list item focusable with Tab key.
titleProvides advisory information (tooltip).Any string<li title=”Click to select”>Item</li><br>Shows tooltip on hover.

2. Element-Specific Attributes

These attributes are tied to specific HTML elements or groups of elements. I’ll cover key elements across categories, focusing on commonly used attributes and including lists for continuity.

A. Document Metadata (<head>, <meta>, <link>, etc.)

ElementAttributeDescriptionPossible ValuesExample
<meta>charsetDefines the character encoding.Encoding (e.g., “UTF-8”)<meta charset=”UTF-8″><br>Ensures proper text rendering.
<meta>name, contentProvides metadata (e.g., description, keywords).Name (e.g., “description”, “viewport”), any string for content<meta name=”description” content=”A fruit list”><br>Improves SEO.
<link>relSpecifies the relationship to the linked resource.“stylesheet”, “icon”, etc.<link rel=”stylesheet” href=”styles.css”><br>Links a CSS file.
<link>hrefSpecifies the resource URL.URL or path<link href=”styles.css”>

B. Structural and Semantic Elements (<div>, <nav>, <main>, etc.)

Most rely on global attributes, but some have specific ones.

ElementAttributeDescriptionPossible ValuesExample
<html>manifestLinks to an application cache (rare).URL to cache file<html manifest=”app.cache”>
<base>hrefSets the base URL for relative links.URL<base href=”https://example.com/”><br>All relative links use this base.

C. Text-Level Elements (<a>, <p>, <span>, etc.)

ElementAttributeDescriptionPossible ValuesExample
<a>hrefSpecifies the link URL.URL, relative path, or anchor (e.g., “#id”)<a href=”https://example.com”>Link</a>
<a>targetDefines where the link opens._self, _blank, _parent, _top<a href=”page.html” target=”_blank”>New tab</a>
<a>relSpecifies the link’s relationship.“nofollow”, “noopener”, “alternate”<a href=”blog.html” rel=”nofollow”>Blog</a>
<abbr>titleProvides the full term for an abbreviation.Any string<abbr title=”HyperText Markup Language”>HTML</abbr>

D. Lists (<ul>, <ol>, <dl>, <li>, <dt>, <dd>)

ElementAttributeDescriptionPossible ValuesExample
<ol>reversedReverses the list order.Boolean (e.g., reversed)<ol reversed><li>3</li><li>2</li></ol><br>Displays 2, 1.
<ol>startSets the starting number/letter.Positive integer<ol start=”5″><li>Item</li></ol><br>Starts at 5.
<ol>typeDefines the numbering style.“1”, “A”, “a”, “I”, “i”<ol type=”A”><li>Item</li></ol><br>Uses uppercase letters (A, B).
<li>valueSets a specific number for an <li> in <ol>.Integer<ol><li value=”10″>Item</li></ol><br>Item numbered 10.

E. Media Elements (<img>, <video>, <audio>, etc.)

ElementAttributeDescriptionPossible ValuesExample
<img>srcSpecifies the image URL.URL or path<img src=”apple.jpg”>
<img>altProvides text for accessibility/SEO.Descriptive string<img src=”apple.jpg” alt=”Red apple”>
<img>width, heightSets image dimensions.Pixels or percentage<img src=”apple.jpg” width=”200″>
<video>controlsShows video controls.Boolean<video controls><source src=”vid.mp4″></video>
<video>autoplayPlays video automatically.Boolean<video autoplay muted>
<audio>loopLoops the audio.Boolean<audio loop><source src=”song.mp3″></audio>

F. Forms (<form>, <input>, <select>, etc.)

ElementAttributeDescriptionPossible ValuesExample
<form>actionURL to send form data.URL<form action=”/submit”>
<form>methodHTTP method for submission.“GET”, “POST”<form method=”POST”>
<input>typeDefines the input type.“text”, “email”, “checkbox”, “radio”, etc.<input type=”email”>
<input>nameIdentifies the input for form submission.String<input name=”username”>
<input>requiredMakes the input mandatory.Boolean<input type=”text” required>
<select>multipleAllows multiple selections.Boolean<select multiple><option>1</option></select>

G. Tables (<table>, <tr>, <td>, etc.)

ElementAttributeDescriptionPossible ValuesExample
<td>colspanSpans multiple columns.Integer<td colspan=”2″>Wide cell</td>
<td>rowspanSpans multiple rows.Integer<td rowspan=”2″>Tall cell</td>

H. Interactive Elements (<details>, <dialog>, etc.)

ElementAttributeDescriptionPossible ValuesExample
<details>openShows content by default.Boolean<details open><summary>List</summary><ul><li>Item</li></ul></details>
<dialog>openDisplays the dialog.Boolean<dialog open><p>Dialog content</p></dialog>

3. Event Attributes

Event attributes trigger JavaScript when specific actions occur (e.g., clicks, keypresses). They are global but typically used with interactive elements like <button>, <input>, or <li>.

AttributeDescriptionPossible ValuesExample
onclickRuns JavaScript on click.JavaScript code<li onclick=”alert(‘Clicked’)”>Item</li>
onchangeTriggers on input change.JavaScript code<input type=”text” onchange=”console.log(this.value)”>
onmouseoverTriggers on hover.JavaScript code<li onmouseover=”this.style.color=’blue'”>Hover me</li>
onkeydownTriggers on key press.JavaScript code<input onkeydown=”console.log(‘Key pressed’)”>
onsubmitTriggers on form submission.JavaScript code<form onsubmit=”alert(‘Submitted’)”>

4. ARIA Attributes (Accessibility)

ARIA (Accessible Rich Internet Applications) attributes enhance accessibility for screen readers and assistive technologies. They’re often used with dynamic content.

AttributeDescriptionPossible ValuesExample
aria-labelProvides a label for elements without visible text.String<ul aria-label=”Fruit list”>
aria-hiddenHides an element from assistive tech.“true”, “false”<li aria-hidden=”true”>Hidden</li>
aria-requiredIndicates a required field.“true”, “false”<input aria-required=”true”>
aria-currentMarks the current item (e.g., in navigation).“page”, “step”, “location”, etc.<li aria-current=”page”>Home</li>

Features

  • Global Attributes: id, class, data-*, tabindex, title, contenteditable.
  • List Attributes: Custom styling via class on <ul>.
  • Form Attributes: action, method, type, required, aria-required.
  • Media Attributes: src, alt, width on <img>.
  • Event Attributes: onclick on <li>, onsubmit on <form>.
  • ARIA Attributes: aria-label, aria-current, aria-required.
html

Related Posts