Skip to content

Attribute

In one line

An HTML attribute is a name-value pair on an element tag that configures or adds extra information to it.

In simple words

Attributes are the extra details you put inside an element's opening tag. They configure how the element behaves or provide additional information. The syntax is name="value", and an element can have multiple attributes separated by spaces.

Common attributes include src (the source URL of an image), href (the destination of a link), class and id (for styling and scripting), alt (alternative text for accessibility), and type (the kind of input field).

Some attributes are boolean — their presence alone is enough, no value needed. For example, <input disabled> disables the input. Attributes are how you customize elements without changing the HTML tag itself.

Example

html
<a href="https://example.com" target="_blank">Open Example</a>

<img src="photo.jpg" alt="A sunset" width="400" />

<input type="email" placeholder="[email protected]" required />

href, target, src, alt, width, type, placeholder, and required are all attributes.

Related terms

Related Resources

Related Lessons

  • HTML

    Attributes are introduced with HTML elements

Learn the fundamentals

Deepen your understanding with structured lessons on this topic.

View lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary