img
The element says what this is: an image embedded in the document.
Learn how attributes configure elements: links, images, classes, ids, forms, metadata, accessibility and custom data.
HTML attributes
Attributes are the settings inside an opening tag. They can give an element a destination, identity, language, source file, validation rule, accessible name, loading strategy or security boundary. The element says what the content is. The attributes configure the details.
Learn attributes by purpose instead of memorizing a flat list. Start with global attributes such as
id, class, lang and hidden, then move into links, media,
metadata, forms, validation, accessibility and security.
<img src="photo.jpg" alt="Auto">
img
The element says what this is: an image embedded in the document.
src
The source attribute tells the browser which image file to load.
"photo.jpg"
The value belongs to src. It points to the image file.
alt
The alt attribute gives the image a text alternative for accessibility and fallback.
"Auto"
The value belongs to alt. It should describe the image meaning in context.
<img src="photo.jpg" alt="Auto">
The img element is a void element, so it does not get a closing </img> tag.
href, src, method, type and defer change how elements work.
lang, alt, aria-label and scope help users and tools understand the page.
rel, sandbox, integrity, validation rules and data hooks reduce surprises later.
id, class, title, hidden, tabindex, lang, dir, styleAttributes that can be used on many HTML elements.
Class and IDclass, idReusable CSS hooks, unique anchors and label targets.
Languagelang, dir, translateLanguage and writing direction for browsers, translation tools and assistive technology.
Datadata-*Custom data stored in HTML for JavaScript and small interface state.
Linkshref, target, rel, download, hreflangAttributes that decide where links go and how safely they open.
Mediasrc, alt, srcset, sizes, loading, width, heightAttributes for images, video, audio and responsive media loading.
Metadatacharset, name, content, http-equiv, relAttributes inside the document head for browsers, SEO and sharing previews.
Formsaction, method, enctype, target, autocomplete, novalidateAttributes that control where forms submit and how browsers help users.
Inputstype, name, value, placeholder, min, max, stepAttributes that shape input fields, keyboard behavior and submitted data.
Validationrequired, minlength, maxlength, pattern, min, max, stepBrowser validation attributes that catch simple mistakes before submit.
Booleandisabled, checked, selected, readonly, multiple, autofocusAttributes where presence means true and absence means false.
Accessibilityaria-*, role, aria-label, aria-labelledby, aria-describedbyAttributes that help assistive technology understand interface intent.
Tablesscope, colspan, rowspan, headersAttributes for data relationships inside real tables.
Scriptssrc, type, defer, async, nomodule, integrity, crossoriginAttributes that control JavaScript loading, modules and security checks.
Iframessrc, title, sandbox, allow, loading, referrerpolicyAttributes for embedded pages, permissions and isolation.
Securityrel, sandbox, integrity, crossorigin, referrerpolicyAttributes that reduce risk when loading or linking external resources.
Eventsonclick, onchange, onsubmit, oninputInline event attributes and why production code usually prefers JavaScript listeners.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.