ADVERTISEMENTS

HTML Attributes

In HTML, attributes provide additional information about an element. They are used to modify the behavior or appearance of an element or to provide additional data that is associated with the element. Attributes are specified using the element's start tag and take the form of name-value pairs. Here are some commonly used HTML attributes:

Id

Specifies a unique identifier for the element, which can be used to refer to the element from CSS or JavaScript.

<div id="header">This is the header.</div>

Class

Specifies one or more CSS classes to apply to the element, which can be used to style the element using CSS.

<div class="container">
  <p class="intro">Welcome to my website.</p>
  <p class="content">Here is some content.</p>
</div>

 

ADVERTISEMENTS

Href

Specifies the URL of the linked resource for <a> elements.

<a href="https://example.com">Visit our website</a>

Src

Specifies the URL of the media file for <img>, <audio>, and <video> elements.

<img src="image.jpg" alt="A beautiful landscape">
<audio src="music.mp3" controls></audio>
<video src="video.mp4" controls></video>

ALT

Specifies an alternative text for an image in case the image cannot be displayed.

<img src="image.jpg" alt="A beautiful landscape">

 

ADVERTISEMENTS

Title

Specifies a tooltip text for the element, which is displayed when the user hovers over the element.

<a href="https://etutorialz.com" title="Visit our website">Click here</a>

Style

Specifies inline CSS styles for the element.

<p style="color: red; font-size: 24px;">This text is styled with inline CSS.</p>

Each HTML element may have its own set of attributes, so it's important to consult the documentation or reference materials for the element that you're working with to see what attributes are available.

ADVERTISEMENTS