Subscribe Us

HTML ATTRIBUTES

Understanding HTML Attributes: Enhance Your Web Content

Understanding HTML Attributes: Enhance Your Web Content

What are HTML Attributes?

HTML attributes provide additional information about HTML elements. They are written inside the opening tag of an element and usually come in name-value pairs.

Common HTML Attributes

Here are some commonly used HTML attributes:

  • href: Specifies the URL for a link. Example: <a href="https://www.example.com">Visit Example</a>
  • src: Specifies the path to an image file. Example: <img src="image.jpg" alt="Description">
  • alt: Provides alternative text for an image. Example: <img src="image.jpg" alt="Example Image">
  • class: Assigns one or more class names to an element for styling purposes. Example: <div class="container">Content</div>
  • id: Assigns a unique identifier to an element. Example: <h1 id="main-heading">Main Heading</h1>

Example: Using Attributes

Here’s an example of HTML code with various attributes:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Attributes Example</title>
</head>
<body>
<h1 id="header" class="main-heading">Welcome to HTML</h1>
<p>Visit Example.com for more information.


<img src="example.jpg" alt="Example Image">
</body>
</html>

© 2024 HTML Tutorial

No comments