VS Vikesh Singh

Courses HTML Lesson 12

HTML · LESSON 12 OF 18

HTML Attributes You're Probably Ignoring

· 4 min read

You've used plenty of attributes already: `href`, `src`, `alt`, `id`, `for`, `type`.

You've used plenty of attributes already: href, src, alt, id, for, type. This lesson steps back and looks at attributes as a general concept, plus a handful of genuinely useful ones that beginners tend to skip entirely, usually because no tutorial mentioned them.

What Attributes Do

An attribute always lives inside an opening tag, written as name="value", and it modifies or adds information to that specific element. You can usually combine several attributes on one tag, separated by spaces, in any order:

<a href="suits.html" target="_blank" rel="noopener noreferrer" title="See all Iron Man suit models">Browse Suits</a>

Adding Tooltips With Title

That title attribute at the end is worth pausing on, because it works on almost any HTML element, not just links, and most beginners never use it. It shows a small tooltip when a visitor hovers their mouse over the element.

<p title="Iron Man's real name">Tony Stark built his first suit in a cave.</p>

Hover over that paragraph in a browser and a small box appears showing the title text after a short delay. It's subtle, it's easy to overuse into annoyance, but used sparingly on things like abbreviations or clarifying notes, it adds a layer of extra context without cluttering the visible page.

Class And Id Explained

Next: the class and id attributes. You've used id already to link labels to inputs and to create jump-to links. class is similar but meant for grouping, not uniqueness. Multiple elements can share the same class, while an id should appear exactly once per page.

<p class="warning">Do not test the repulsors indoors.</p>
<p class="warning">Always wear safety goggles in the workshop.</p>

Neither class nor id changes anything visually on their own in plain HTML; they're hooks meant for CSS and JavaScript to target later. We mention them here because they're genuinely HTML attributes you'll rely on constantly once you reach CSS, so it's worth knowing their purpose even before using them for styling.

Disabled And Required Inputs

Now, the disabled attribute, commonly used on form elements, which you saw briefly but didn't examine closely in the forms lesson:

<button type="submit" disabled>Send Message</button>

A disabled button appears grayed out and cannot be clicked or focused at all. This is genuinely useful for situations like preventing a form submission until required fields are filled, though actually wiring up that logic requires JavaScript; plain HTML can only set the disabled state, not toggle it dynamically on its own.

Here's one beginners almost universally skip: the required attribute on form inputs.

<input type="email" id="contact-email" name="contact-email" required>

With required present, a browser will automatically refuse to submit the form at all if that field is left empty, popping up a small built-in warning message, with zero JavaScript involved. We'll dig much deeper into this exact behavior in the dedicated form validation lesson later in this course; for now, just recognize required as a real, functioning attribute, not a suggestion.

Boolean And Lesser-Known Attributes

Boolean attributes deserve a specific mention, since they look unusual compared to name="value" attributes. disabled, required, checked, autoplay, and controls from the previous lesson are all boolean: their mere presence turns the behavior on, and there's no real value to assign. You don't write disabled="true"; you simply write disabled, or you omit it entirely to leave that behavior off.

<input type="checkbox" id="subscribe" name="subscribe" checked>

This checkbox starts pre-checked when the page loads, because checked is present, full stop. No value needed.

The tabindex attribute controls keyboard navigation order, and it's worth knowing even though you'll rarely need to touch it. By default, a visitor pressing Tab moves through focusable elements, links, buttons, inputs, in the order they appear in your HTML source. tabindex="0" can make a normally non-focusable element, like a <div>, become reachable by Tab, which occasionally matters for custom interactive widgets, though that's more of a JavaScript-era concern than a plain HTML habit to reach for often.

A quietly useful one: spellcheck.

<textarea id="message" name="message" spellcheck="true"></textarea>

Most browsers already spellcheck text areas by default, but explicitly setting it, or setting spellcheck="false" for something like a code snippet input where red squiggly underlines would be distracting and wrong, shows you understand the attribute exists and what it controls.

Quoting Values Correctly

A common mistake across all attributes: forgetting quotes around values, or mixing quote styles inconsistently, like <a href=suits.html>. Most browsers tolerate unquoted attribute values when there are no spaces involved, but it's fragile and becomes an actual error the moment a value contains a space, like a title with multiple words. Always quote attribute values, consistently, no exceptions, even when a browser would technically let you skip it.

Hands-on check: take a form you built in an earlier lesson and add required to at least one input, title to one element as a hover tooltip, and disabled to a spare button you don't intend to wire up yet. Try submitting the form with the required field empty and watch the browser's built-in warning appear on its own.