Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to HTML Notes
Topic #110

HTML Attributes

Attributes add extra information to an element — they live inside the opening tag as name-value pairs.

Syntax

<tagname attribute="value">content</tagname>

Example

<a href="https://codingnowai.in" target="_blank" rel="noopener">
    Visit CodingNow
</a>

This anchor has three attributes: href (destination), target (open in a new tab), and rel (security relationship — see rel attribute).

Common Attribute Categories

TypeExamples
Universal / globalid, class, style, title — usable on almost any element. See Global Attributes.
Element-specifichref (only on <a>), src (only on <img>/<video>/etc.)
Booleandisabled, required, checked — presence alone means "true"
Customdata-* attributes — see Data Attributes

Boolean Attributes — A Common Point of Confusion

<!-- Correct: presence alone disables the button -->
<button disabled>Submit</button>

<!-- Also correct, but the value is ignored either way -->
<button disabled="disabled">Submit</button>

<!-- WRONG assumption: this does NOT enable the button -->
<button disabled="false">Submit</button>

Boolean attributes don't check their value — only whether they're present at all. disabled="false" still disables the button, which surprises almost everyone the first time.

Quoting Values

Always quote attribute values, even when HTML5 technically allows omitting quotes for simple values. It's required the moment a value contains a space, and consistent quoting avoids bugs entirely.

Common Mistakes

  • The boolean-attribute trap above (disabled="false" still disabling the element)
  • Forgetting quotes around attribute values that contain spaces
  • Using the wrong attribute for the element (e.g. href on an <img> instead of src)

Interview Relevance

Q: "Does disabled="false" enable a button?" No — a favorite trick question testing whether you understand boolean attributes correctly.

Practice Question

Write an <input> element that is required, has a placeholder of "Enter your email," and is of type email.

Related HTML Notes

Want to go beyond the notes?

Join CodingNow's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →