HTML attributes provide additional information about HTML elements. They are used to modify the behavior or appearance of HTML tags. Attributes are placed within the opening tag of an element and consist of a name and a value, separated by an equals sign (=). The value is enclosed in quotation marks.
Here are some commonly used HTML attributes:
class: Specifies one or more CSS class names for an element. It is used to style and group elements with similar characteristics. Example: <div class="container">...</div>
id: Specifies a unique identifier for an element. It is used to uniquely identify and style specific elements within the document. Example: <h1 id="title">...</h1>
style: Defines inline CSS styles for an element. It is used to apply specific styling directly to the element. Example: <p style="color: red;">...</p>
src: Specifies the source URL of an external resource, such as an image or a script. Example: <img src="image.jpg" alt="Image">
href: Defines the URL or destination of a hyperlink. Example: <a href="https://www.example.com">...</a>
alt: Provides alternative text for an image, to be displayed when the image cannot be loaded or for accessibility purposes. Example: <img src="image.jpg" alt="Description of the image">
width and height: Specifies the width and height dimensions of an element, such as an image or a table cell. Example: <img src="image.jpg" width="200" height="150" alt="Image">
disabled: Disables an input field, button, or other form element, preventing user interaction. Example: <input type="text" disabled>
placeholder: Provides a short hint or example value for an input field. Example: <input type="text" placeholder="Enter your name">
required: Specifies that an input field must be filled out before submitting a form. Example: <input type="text" required>
target: Defines where to open the linked document when clicking on a hyperlink. Example: <a href="https://www.example.com" target="_blank">...</a>
These are just a few examples of HTML attributes. Each HTML element may have different attributes that are specific to its functionality and purpose. Attributes play a crucial role in customizing and enhancing the behavior and appearance of HTML elements within a web page.