Geek Slack

Introduction to HTML
About Lesson


HTML Attributes


HTML Attributes

HTML attributes provide additional information about HTML elements. They are always included in the opening tag and consist of a name and a value, separated by an equals sign (=).

Basic Structure of HTML Attribute

An HTML attribute is defined within the opening tag of an element:

Example of an HTML attribute:

<a href="https://www.example.com">Visit Example.com</a>

Common HTML Attributes

Here are some common HTML attributes:

  • id – Specifies a unique identifier for an element
  • class – Specifies one or more class names for an element (for styling with CSS)
  • src – Specifies the URL of an image or other media file
  • href – Specifies the URL of the linked resource
  • alt – Specifies an alternate text for an image
  • style – Specifies inline CSS styles for an element
  • title – Specifies extra information about an element (often displayed as a tooltip)

Example: Using Attributes in HTML Elements

Example of using attributes in HTML elements:

<img src="example.jpg" alt="Example Image" title="This is an example image">

Conclusion

HTML attributes play a crucial role in defining the behavior, appearance, and functionality of HTML elements. Understanding how to use attributes effectively enhances the structure and presentation of web pages.

Join the conversation