What are HTML Attributes?
HTML attributes provide additional information about HTML elements. Attributes are always specified in the opening tag and usually come in name/value pairs like name="value"
.
Common HTML Attributes
Some common HTML attributes include:
href
- Specifies the URL of a link.src
- Specifies the path of an image.alt
- Provides alternative text for images.style
- Adds inline CSS styles to an element.class
- Assigns a class name to an element for styling purposes.
Example of HTML Attributes
<a href="https://example.com">Visit Example Website</a>
<img src="image.jpg" alt="Sample Image" style="width:200px;height:100px;">
Try It Yourself
Quiz: Test Your Knowledge
Which attribute is used to specify the URL for a link?
Coding Challenge
Create a link that opens the OpenAI website in a new tab, and add an image with an alt text of your choice below the link.