HTML Attributes Cheatsheet

Complete reference of HTML attributes for modern web development

Global Attributes 13 attributes

accesskey

Specifies a shortcut key to activate/focus an element

<button accesskey="s">

contenteditable

Specifies whether the content of an element is editable

<div contenteditable="true">

data-*

Used to store custom data private to the page or application

<div data-id="123">

dir

Specifies the text direction for the content in an element

<p dir="rtl">

draggable

Specifies whether an element is draggable or not

<img draggable="true">

hidden

Specifies that an element is not yet, or is no longer, relevant

<div hidden>

id

Specifies a unique id for an element

<div id="header">

lang

Specifies the language of the element's content

<html lang="en">

spellcheck

Specifies whether the element is to have spelling and grammar checked

<input spellcheck="true">

style

Specifies an inline CSS style for an element

<div style="color:red">

tabindex

Specifies the tab order of an element

<input tabindex="1">

title

Specifies extra information about an element (as a tooltip)

<abbr title="Hypertext Markup Language">

translate

Specifies whether the content should be translated or not

<p translate="no">

Form Attributes 18 attributes

action

Specifies where to send the form data when a form is submitted

<form action="/submit">

method

Specifies the HTTP method (GET or POST) to use when sending form data

<form method="post">

enctype

Specifies how form data should be encoded when submitting it

<form enctype="multipart/form-data">

autocomplete

Specifies whether the browser should autocomplete form fields

<form autocomplete="off">

novalidate

Specifies that the form should not be validated when submitted

<form novalidate>

target

Specifies where to display the response after submitting the form

<form target="_blank">

accept-charset

Specifies the character encodings the server can handle

<form accept-charset="UTF-8">

name

Specifies the name of the form

<form name="loginForm">

rel

Specifies the relationship between the current document and the linked resource

<form rel="noopener">

accept

Specifies the types of files that the server accepts (only for file upload)

<input type="file" accept="image/*">

disabled

Disables the input or form control

<input disabled>

readonly

Makes an input field read-only (cannot be edited)

<input readonly>

multiple

Allows multiple values to be selected in input fields like file or select

<input type="file" multiple>

required

Specifies that an input field must be filled out before submitting

<input required>

placeholder

Provides a short hint that describes the expected value of an input field

<input placeholder="Enter name">

pattern

Specifies a regex pattern that the input value must match

<input pattern="[0-9]{3}">

maxlength

Specifies the maximum number of characters allowed in an input field

<input maxlength="10">

size

Specifies the width of the input field in characters

<input size="40">

Media Attributes 8 attributes

src

Specifies the URL of the media file

<img src="image.jpg">

alt

Specifies an alternate text for images

<img alt="Descriptive text">

controls

Specifies that video/audio controls should be displayed

<video controls>

autoplay

Specifies that the media will start automatically

<video autoplay>

loop

Specifies that the media will start over when finished

<video loop>

poster

Specifies an image to be shown while video is downloading

<video poster="image.jpg">

muted

Specifies that the audio output should be muted

<video muted>

preload

Specifies if and how the author thinks the media should be loaded

<video preload="auto">

Meta Attributes 8 attributes

charset

Specifies the character encoding for the HTML document

<meta charset="UTF-8">

name

Specifies the name for metadata (like description, keywords, viewport)

<meta name="description">

content

Specifies the value associated with the name or http-equiv attribute

<meta name="description" content="Free tutorials">

http-equiv

Provides an HTTP header for the information/value of the content attribute

<meta http-equiv="refresh" content="30">

viewport

Controls the viewport's size and scale for responsive design

<meta name="viewport" content="width=device-width, initial-scale=1.0">

X-UA-Compatible

Specifies which version of Internet Explorer should be used to render the page

<meta http-equiv="X-UA-Compatible" content="IE=edge">

robots

Specifies the behavior of search engine crawling and indexing

<meta name="robots" content="index, follow">

author

Specifies the name of the document's author

<meta name="author" content="John Doe">

ARIA Attributes 10 attributes

aria-label

Defines a string label for an element, improving accessibility for screen readers

<button aria-label="Close">

aria-hidden

Indicates whether an element is visible or hidden to assistive technologies

<div aria-hidden="true">

aria-checked

Indicates the current checked state of checkboxes, radio buttons, or menu items

<input type="checkbox" aria-checked="true">

aria-disabled

Indicates that the element is disabled and cannot be interacted with

<button aria-disabled="true">

aria-expanded

Indicates whether an element, like a collapsible section, is expanded or collapsed

<button aria-expanded="false">

aria-current

Indicates the current item in a set of items, such as a navigation menu

<a aria-current="page">

aria-required

Indicates that user input is required on the element before form submission

<input aria-required="true">

aria-live

Indicates that an element will be updated and live regions should be announced to users

<div aria-live="polite">

role

Defines the role of an element (e.g., button, dialog, navigation) for assistive technologies

<div role="dialog">

aria-controls

Identifies the element(s) that are controlled by the current element

<button aria-controls="menu">

Event Attributes 24 attributes

onclick

Fires when an element is clicked by the user

<button onclick="myFunction()">

ondblclick

Triggered when an element is double-clicked

<div ondblclick="alert('Hi!')">

onmouseover

Occurs when the mouse pointer moves over an element

<img onmouseover="hoverEffect()">

onmouseout

Fires when the mouse pointer moves out of an element

<div onmouseout="removeHighlight()">

onmousedown

Fires when a mouse button is pressed down on an element

<button onmousedown="startAction()">

onmouseup

Occurs when the mouse button is released over an element

<div onmouseup="stopAction()">

onkeydown

Fires when a key is pressed down on the keyboard

<input onkeydown="detectKey()">

onkeyup

Occurs when a key is released after being pressed

<input onkeyup="checkValue()">

onkeypress

Fires when a key is pressed and held down

<textarea onkeypress="logChar()">

onchange

Triggered when the value of an element changes

<select onchange="updateOption()">

oninput

Occurs when an input field receives user input

<input oninput="checkInput()">

onfocus

Fires when an element gains focus

<input onfocus="highlight()">

onblur

Occurs when an element loses focus

<input onblur="removeHighlight()">

onload

Fires when a page or image finishes loading

<body onload="initPage()">

onunload

Triggered when a document is unloaded or the user leaves the page

<body onunload="cleanup()">

onsubmit

Occurs when a form is submitted

<form onsubmit="validateForm()">

onreset

Triggered when a form is reset

<form onreset="clearFields()">

onresize

Fires when the browser window is resized

<body onresize="adjustLayout()">

onscroll

Occurs when an element or window is scrolled

<div onscroll="loadMore()">

oncontextmenu

Fires when the context menu is triggered (right-click)

<div oncontextmenu="showMenu()">

ondrag

Occurs when an element is being dragged

<div ondrag="dragging()">

ondrop

Triggered when an element is dropped in a valid drop target

<div ondrop="handleDrop()">

onerror

Fires when an error occurs while loading an external file like image or script

<img src="invalid.jpg" onerror="alert('Error loading image')">

onwheel

Fires when the mouse wheel is scrolled over an element

<div onwheel="zoomImage()">Scroll here</div>