HTML attributes are additional information added to HTML tags that define properties, behavior, or appearance of an element.
Attributes are written inside the opening tag and usually come in name="value" format.
Syntax
<tagname attribute="value">Content</tagname>
Common Examples of Attributes
- Global Attributes (can be used on most HTML elements)
-
id→ unique identifier<div id="header">Header</div> -
class→ CSS class for styling<p class="text-primary">Hello World</p> -
style→ inline CSS<h1 style="color: red;">Title</h1> -
title→ tooltip text<button title="Click me!">Button</button>
- Link & Anchor Attributes
-
href→ URL for<a><a href="https://example.com">Visit Example</a> target→_blank(open in new tab)
- Image Attributes
src→ image URL-
alt→ alternate text<img src="logo.png" alt="Company Logo">
- Form/Input Attributes
type→ input type (text,email,password)name→ key used when submitting form datavalue→ default valueplaceholder→ hint text-
required→ makes input mandatory<input type="email" name="email" placeholder="Enter email" required>
- Media Attributes
controls→ show video/audio controls-
autoplay→ play automatically<video src="video.mp4" controls></video>
💡 In Short:
Attributes enhance HTML elements by providing extra information, controlling behavior, styling, linking, or accessibility. Examples include
id,class,src,href,alt,type,placeholder, andrequired.