HTML Attributes
HTML attributes provide additional information about elements. They are always specified in the opening tag.
Common Attributes
id
: Unique identifier for an element.class
: Specifies one or more class names for an element.src
: Specifies the source URL for media elements.href
: Specifies the URL for links.alt
: Provides alternative text for images.style
: Adds inline CSS styles to an element.title
: Provides additional information about an element (tooltip).
Example: HTML Attributes
<img src="image.jpg" alt="Description of the image" width="300" height="200">
<a href="https://example.com" title="Visit Example">Example</a>
<p class="highlight" style="color: red;">This is a styled paragraph.</p>
Boolean Attributes
Boolean attributes (e.g., disabled
, checked
) do not require a value.
<input type="checkbox" checked>
<button disabled>Submit</button>
Custom Attributes
You can define custom attributes using the data-*
attribute.
<div data-user-id="12345" data-role="admin">User Info</div>
Next: HTML Forms