HTML attributes are used to provide additional information or modify the behavior of HTML elements. They are defined within the opening tag of an HTML element and consist of a name-value pair. Here are some commonly used HTML attributes:
1. **class**: Specifies one or more class names for an element. It is used to associate the element with CSS styles or JavaScript functions.
html
<div class="container">...</div>
2. **id**: Specifies a unique identifier for an element. It is often used to target specific elements with CSS or JavaScript.
html
<p id="myParagraph">...</p>
3. **style**: Defines inline CSS styles for an element. It allows you to specify properties like color, font-size, padding, etc., directly within the HTML tag.
html
<span style="color: red; font-weight: bold;">Hello</span>
4. **src**: Specifies the source URL of an external resource, such as an image or a script.
html
<img src="image.jpg" alt="Image">
<script src="script.js"></script>
5. **href**: Specifies the URL of a linked resource, such as a web page or a file.
html
<a href="https://www.example.com">Visit Example</a>
<a href="document.pdf">Download PDF</a>
6. **alt**: Provides alternative text for an image, which is displayed if the image cannot be loaded.
html
<img src="image.jpg" alt="Description of the image">
7. **disabled**: Disables an input field, button, or any interactive element, preventing user interaction.
html
<input type="text" disabled>
<button disabled>Click me</button>
8. **placeholder**: Displays a short hint or example text within an input field before the user enters a value.
html
<input type="text" placeholder="Enter your name">
9. **target**: Specifies where to open a linked resource. For example, "_blank" opens the link in a new window or tab.
html
<a href="https://www.example.com" target="_blank">Open in new tab</a>
These are just a few examples of HTML attributes. There are many more attributes available depending on the HTML element you are working with.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc