HTML Attribute Reference Guide – Complete List & Usage

Learn HTML attributes with a complete reference list, explanations, usage, global attributes, events, forms, media, and best practices for developers.

HTML Attribute Reference – Complete & Easy Guide

HTML attributes are special words written inside HTML tags. They give extra information about an element or control how that element behaves. Without attributes, HTML would be very limited and static.

This detailed guide explains what HTML attributes are, how they work, and provides a complete reference of attributes, including global attributes, form attributes, media attributes, and event attributes.


What Is an HTML Attribute?

An HTML attribute modifies or adds meaning to an HTML element.

Basic Syntax

<tag attribute="value">Content</tag>

Example

<img src="photo.jpg" alt="A beautiful sunset">
  • src → tells the browser where the image is
  • alt → provides alternative text if the image cannot load

Types of HTML Attributes

HTML attributes can be grouped into logical categories:

  1. Global Attributes – Can be used on almost all HTML elements
  2. Element-Specific Attributes – Work only with certain tags
  3. Form Attributes – Used with form elements
  4. Media Attributes – Used with audio and video
  5. Event Attributes – Trigger JavaScript actions

Global Attributes (Work on Almost All Elements)

Global attributes improve accessibility, interaction, and styling.

AttributeDescription
idUnique identifier for an element
classAssigns one or more CSS classes
styleAdds inline CSS
titleExtra information on hover
langLanguage of content
dirText direction (ltr / rtl)
hiddenHides the element
contenteditableMakes content editable
tabindexControls keyboard navigation
spellcheckEnables/disables spelling check
translateControls auto-translation
draggableMakes element draggable
inertMakes content inactive
data-*Stores custom data
popoverDefines a popover UI
accesskeyKeyboard shortcut
inputmodeVirtual keyboard type
enterkeyhintLabel for enter key

Form-Related Attributes

Used to control form submission, validation, and user input.

AttributeBelongs ToPurpose
action<form>URL to send form data
method<form>HTTP method (GET/POST)
enctype<form>Encoding type
autocomplete<form>, <input>Enables auto-fill
novalidate<form>Skips validation
required<input>, <select>Mandatory field
readonly<input>, <textarea>Read-only input
disabledForm controlsDisables element
placeholder<input>, <textarea>Hint text
pattern<input>Regex validation
maxlength<input>, <textarea>Character limit
min, max, stepInputsNumeric limits
multiple<input>, <select>Multiple values
checked<input>Pre-selected checkbox
selected<option>Pre-selected option
list<input>Connects <datalist>
dirnameInputsSubmits text direction

Media Attributes (Audio & Video)

Control playback behavior of media elements.

AttributeDescription
srcMedia source URL
controlsShows play/pause buttons
autoplayPlays automatically
loopRepeats media
mutedMutes sound
preloadLoads media in advance
posterPreview image for video
kindTrack type (subtitles, captions)
srclangLanguage of subtitles
defaultDefault track

Image & Resource Attributes

Used with images, links, and external resources.

AttributeUsed WithPurpose
srcImages, mediaFile URL
altImagesAlternative text
width, heightMediaDimensions
srcsetImagesResponsive images
sizesImagesImage size rules
usemapImagesImage maps
ismapImagesServer-side maps
hrefLinksDestination URL
targetLinks, formsOpen behavior
downloadLinksForce download
relLinksRelationship
hreflangLinksLanguage of target
mediaLinks, stylesMedia conditions

Table & List Attributes

Used for structured data and lists.

AttributeElementDescription
colspan<td>, <th>Column span
rowspan<td>, <th>Row span
headersTable cellsHeader association
scope<th>Header scope
span<col>, <colgroup>Column span
start<ol>Starting number
reversed<ol>Descending order
value<li>List item value

Event Attributes (JavaScript Events)

Event attributes execute JavaScript when something happens.

Mouse Events

  • onclick
  • ondblclick
  • onmouseover
  • onmouseout
  • onmousemove
  • onmousedown
  • onmouseup
  • onwheel

Keyboard Events

  • onkeydown
  • onkeypress
  • onkeyup

Form Events

  • onchange
  • oninput
  • onsubmit
  • onreset
  • oninvalid
  • onselect

Media Events

  • onplay
  • onpause
  • onended
  • onvolumechange
  • ontimeupdate
  • onwaiting
  • onprogress

Window & Document Events

  • onload
  • onresize
  • onscroll
  • onoffline
  • ononline
  • onunload
  • onpagehide
  • onpageshow
  • onpopstate
  • onhashchange
  • onstorage

Deprecated Attributes (Avoid in HTML5)

These attributes are not supported in HTML5 and should be replaced with CSS.

AttributeReason
alignUse CSS alignment
bgcolorUse CSS background
borderUse CSS border
colorUse CSS color
bigUse CSS font-size
acronymUse <abbr>

Best Practices for Using HTML Attributes

  • ✅ Use semantic attributes for clarity
  • ✅ Prefer CSS over deprecated attributes
  • ✅ Always include alt for images
  • ✅ Use label with for for accessibility
  • ❌ Avoid inline event handlers when possible

Final Thoughts

HTML attributes are the building blocks of interactive, accessible, and responsive web pages. Understanding which attribute belongs to which element helps you write clean, valid, and modern HTML.

This reference serves as a complete, beginner-friendly, and professional guide to all major HTML attributes used in real-world web development.

Similar Posts

Leave a Reply