HTML – Attribute


HTML – Attribute

In HTML, attributes provide additional information about an element. They are used to modify or enhance the behaviour and appearance of HTML elements. Attributes are always specified in the opening tag of an element and are written as name-value pairs. Here’s an overview of HTML attributes:

Syntax of Attributes

  • Attributes are added to an element within its opening tag.
  • They consist of a name and a value, separated by an equals sign (=).
  • The value is enclosed in double or single quotes.
<tagname attribute="value">Content...</tagname>

Common HTML Attributes

  •  HTML elements support various attributes, each with its specific purpose.
  • Common attributes include id, class, src, href, alt, width, height, and many more.
<img src="image.jpg" alt="An example image" width="300" height="200">
  • Example 1
  • Example 2

Attributes for Links (Anchor Elements)

  • The <a> element is commonly used to create hyperlinks.
  • Attributes like href specify the URL that the link points to.
<a href="">Visit Example</a>

Attributes for Images

  • The <img> element is used to display images.
  • Attributes like src define the image source and alt provide alternative text.
<img src="image.jpg" alt="An example image">

Attributes for Forms

  • HTML forms use attributes like action to specify the form’s action URL and method to define the HTTP method (GET or POST).
<form action="submit.php" method="POST">
<!-- Form elements here -->

Attributes play a crucial role in making HTML elements interactive, informative, and visually appealing. Understanding how to use attributes effectively is an essential skill in web development.

YouTube Reference :