HTML Attributes
HTML attributes are used to provide additional information or modify the behavior of HTML elements. They are specified within the opening tag of an HTML element and are typically written as key-value pairs. Here are some commonly used HTML attributes:
id: Specifies a unique identifier for an element within the document.
Example: <div id=”myDiv”>…</div>
class: Specifies one or more CSS class names to apply to an element.
Example: <p class=”highlight”>…</p>
style: Specifies inline CSS styles to be applied to an element.
Example: <h1 style=”color: blue;”>…</h1>
src: Specifies the source URL of an external resource, such as an image or a script.
Example: <img src=”image.jpg” alt=”Image”>
href: Specifies the URL of a linked resource, such as a webpage or a file.
Example: <a href=”https://www.example.com”>…</a>
alt: Provides alternative text for an image, to be displayed if the image cannot be loaded.
Example: <img src=”image.jpg” alt=”Image description”>
disabled: Indicates that an input element or button is disabled and cannot be interacted with.
Example: <input type=”text” disabled>
placeholder: Provides a short hint or example text within an input element.
Example: <input type=”text” placeholder=”Enter your name”>
required: Specifies that an input element must be filled out before submitting a form.
Example: <input type=”text” required>
target: Specifies the browsing context for a link navigation or form submission.
Example: <a href=”https://www.example.com” target=”_blank”>…</a>
These are just a few examples of HTML attributes. Different HTML elements have different attributes available to them. It’s important to refer to the HTML specification or relevant documentation for a comprehensive list of attributes supported by each element.