HTML Attributes

HTML Attributes


  •  It is used to define the characteristics of an HTML element.
  •  It is placed in the opening tag of the HTML element.
  •  All attributes are made up of two parts: Name and Value.

What are the different types of Attributes?

There are three types of attribute:

  •  Core Attributes
  •  Internationalization Attributes
  •  Generic Attributes

HTML Core Attributes

The most widely used attribute is core attributes. There are 4 types of core attributes:

  •       Id
  •       Class
  •       Title
  •      Style

HTML Attributes Code:

2. Learn how to add attributes to HTML elements:
Attributes are added to HTML elements using the element's starting tag. The general format for adding an attribute is as follows:
HTML Attributes Code:

3. Explore common HTML attributes:
There are many different HTML attributes that can be used to modify the behavior and appearance of elements. Here are some of the most commonly used attributes:
  • "id": This attribute sets a unique identifier for an element, which can be used to target the element in CSS or JavaScript.
  • "class": This attribute sets one or more class names for an element, which can be used to apply CSS rules to multiple elements at once.
  • "style": This attribute sets inline CSS styles for an element, allowing you to modify its appearance directly.
  • "src": This attribute specifies the URL of an image or other media file to be displayed in an element, such as an `<img>` tag.
  • "href": This attribute specifies the URL of a link destination for an `<a>` tag.
  • "title": This attribute sets a tooltip that appears when a user hovers over an element.
  • "alt": This attribute sets alternative text that is displayed when an image or other media file cannot be loaded.