What Are HTML Attributes?

HTML attributes provide additional information about HTML elements and are always included in the opening tag. 
Here are some commonly used HTML attributes:

1. class Attribute:

Defines one or more class names for an HTML element. Used to link an element with a style in a style sheet or to reference an element with JavaScript.
   html
   <div class=”container”>
       <!– Content goes here –>
   </div>
HTML Attributes | class and id Attribute - style and src Attribute - alt and href Attribute - disabled Attribute - Some commonly used HTML attributes
HTML Attributes

2. id Attribute:

Defines a unique identifier for an HTML element. Useful for styling or scripting purposes.
   html
   <p id=”uniqueParagraph”>This is a unique paragraph.</p>

3. style Attribute:

Specifies inline CSS styles for an HTML element.
   html
   <p style=”color: red; font-size: 16px;”>This paragraph has inline styles.</p>
   
class and id Attribute - style and src Attribute - alt and href Attribute - disabled Attribute - Some commonly used HTML attributes
Scope of Attributes

4. src Attribute:

Specifies the source URL for external resources, such as images or scripts.
   html
   <img src=”example.jpg” alt=”Example Image”>

5. alt Attribute:

Provides alternative text for an image, to be displayed if the image cannot be loaded.
   html
   <img src=”example.jpg” alt=”Description of the image”>
   
class and id Attribute - style and src Attribute - alt and href Attribute - disabled Attribute - Some commonly used HTML attributes
Run this code in your browser

6. href Attribute:

Specifies the URL of a linked resource, typically used with anchor (<a>) elements.
   html
   <a href=”https://www.example.com”>Visit Example Website</a>

7. width and height Attributes:

Specify the width and height of an element, often used with images.
   html
   <img src=”example.jpg” alt=”Example Image” width=”300″ height=”200″>

8. colspan and rowspan Attributes:

Define the number of columns or rows a table cell should span.

   html
   <td colspan=”2″>This cell spans two columns</td>
   html
   <td rowspan=”3″>This cell spans three rows</td>

9. disabled Attribute:

Indicates that an input element should be disabled, preventing user interaction.
   html
   <input type=”text” disabled>

10. placeholder Attribute:

 Specifies a short hint that describes the expected value of an input field.
    html
    <input type=”text” placeholder=”Enter your name”>
These are just a few examples, and there are many more HTML attributes available for various elements. The use of attributes depends on the specific requirements of your HTML document and the behavior you want to achieve.