Chapter 4 of 17 · HTML for Beginners — Complete Free Tutorial
HTML Attributes
Attributes are name/value pairs inside the opening tag that configure an element. They are how a plain <img> becomes an image with a source, alternative text, and dimensions.
Attribute syntax
<tagname attribute-name="value">...</tagname>
<!-- Real example -->
<img src="bakery-cake.jpg" alt="A chocolate cake on a wooden table" width="800" height="600">
- Attributes go in the opening tag only.
- Always quote values with double quotes — it prevents errors when a value contains spaces.
- Attribute names are lowercase by convention:
class, notCLASS. - An attribute cannot appear twice in the same tag.
The attributes you will use every day
| Attribute | Used on | Purpose |
|---|---|---|
href | <a> | Destination URL of a link |
src | <img>, <script>, <iframe> | Path to the file to load |
alt | <img> | Text alternative for screen readers and broken images |
id | any element | Unique identifier on the page (one per page) |
class | any element | Reusable label for styling/scripting (many per page) |
title | any element | Extra tooltip text — use sparingly |
lang | <html>, <span> | Language of the element's content |
Global attributes
Some attributes work on every element:
id— unique name, useful for anchor links like/page#pricing.class— one element can hold many classes:class="card featured".style— inline CSS. Technically valid, but considered a bad habit — prefer stylesheets.data-*— custom data, e.g.data-category="pastry". Read later by JavaScript.hidden— hides the element completely.tabindex,role,aria-*— accessibility controls, covered in HTML Accessibility.
Boolean attributes
Some attributes act as on/off switches. They have no value — presence means "on":
<input type="checkbox" checked>
<button type="submit" disabled>Send</button>
<video src="tour.mp4" controls muted></video>
Writing checked="false" does not turn the attribute off — in HTML, any value (including "false") means true. To disable it, remove the attribute entirely.
Real-life example: a product card
<article class="product-card" data-category="bread">
<img src="sourdough.jpg" alt="Round sourdough loaf with a scored top" width="640" height="480">
<h3 class="product-card__title">Classic sourdough</h3>
<p>₹220 <span class="stock" id="stock-42">In stock</span></p>
<button type="button" data-sku="BREAD-042" disabled>Add to cart</button>
</article>
Here data-category lets JavaScript filter products, data-sku identifies the item for checkout, and disabled prevents clicks while an item is out of stock.
Common mistakes
- Unquoted values —
alt=Fresh breadbreaks the moment a value has a space. - Duplicate
ids — invalid, and anchor links / CSS selectors will target the wrong element. - Using
titleinstead ofalt— tooltips are not accessible;altis mandatory on images. - Misusing
classvsid— classes for groups, ids for single unique items.
Best practices
- Write
widthandheighton every image — it reserves space and prevents layout shifts (great for Core Web Vitals). - Use descriptive
data-*names instead of stuffing meaning into class names. - Keep attribute order consistent in your team (a common style: element-defining attributes first, then
class, thenid, then data/aria).
What's next?
Now that you can configure elements, build content with Headings, Paragraphs & Text Formatting, or learn how attributes power navigation in Links & Navigation.
Frequently Asked Questions
HTML (HyperText Markup Language) is the standard markup language that defines the structure and meaning of every web page. Learning HTML is the fastest way into web development: it is the foundation that CSS, JavaScript, and every framework build upon, and it directly affects SEO and accessibility.
Most beginners can build their first complete page in a day and become comfortable with the core tags within 1–2 weeks of daily practice. This 17-chapter series is designed to be completed in about 2–3 weeks at a relaxed pace, faster if you type out every example.
Only a plain text editor (VS Code is free and popular) and a web browser. No installation, no setup, no account — create a file called index.html, double-click it, and it opens in your browser.
HTML5 is the current generation of the HTML standard (published as the living standard by WHATWG). When people say "HTML5" they usually mean modern HTML: semantic elements like header, nav and article, native audio/video, canvas, and improved form input types — all covered in this tutorial.
No. HTML is a markup language — it describes content and structure but has no variables, loops, or conditionals. Those come with programming languages like JavaScript, which you would learn after HTML and CSS.
Right here: every chapter includes examples you can retype in your own index.html file, plus practice challenges. After this series, build small projects — a portfolio page, a recipe page, or a landing page for a local business — they exercise the same tags in real contexts.
Search engines crawl HTML first. Unique titles, a single clear h1, a logical heading hierarchy, descriptive alt text, valid markup, fast-loading responsive images, and a proper internal linking structure all come straight from HTML — see the HTML & SEO chapter for the full checklist.
Accessible HTML makes your site usable by everyone, including people who rely on screen readers or keyboards, and it is a legal requirement in many countries. The good news: proper labels, semantic elements, alt text, and keyboard-operable controls are mostly free HTML habits.
No — there are roughly 100 meaningful tags and you will naturally use about 30 of them regularly. Focus on understanding purpose and structure; editors and references (like MDN) handle the rest. This tutorial covers every tag beginners actually need.
CSS for visual design and layout, then JavaScript for interactivity, then a version control system (Git). With those three you can build complete websites; frameworks like React or Laravel Blade come after the fundamentals feel natural.