HTML Attributes - Detailed Overview

Introduction to HTML Attributes

HTML attributes provide additional information about HTML elements. They are always specified in the opening tag of an element and come in name-value pairs, separated by an equal sign. Attributes can control various aspects of an element, such as its appearance, behavior, and functionality.

Common HTML Attributes

Some common HTML attributes include id, class, style, href, and src. Below are examples of how these attributes are used in HTML elements:

Example 1: Using the id and class Attributes

The id attribute provides a unique identifier for an element, while the class attribute specifies one or more class names for styling purposes:

<div id="container" class="box">
    <p class="text">This is a paragraph.</p>
</div>

This is a paragraph.

Example 2: Using the style, href, and src Attributes

The style attribute applies inline CSS styles to an element. The href attribute specifies the URL of a linked resource (used in <a> tags), and the src attribute specifies the URL of an image (used in <img> tags):

<a href="https://www.shariqsp.com">Visit Example</a>
<img src="https://www.shariqsp.com/apple-touch-icon.png" alt="Example Image" style="border: 1px solid #ddd;" />