CodeToLive

HTML Attributes

HTML attributes provide additional information about elements. They are always specified in the opening tag.

Common Attributes

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