HTML Attributes
Attributes give extra information about an element and always sit in its start tag.
All HTML elements can have attributes. They usually come as a name and a value in the form name="value", and they tell the element how to behave or where to find something.
The href Attribute
The <a> element creates a link, and its href attribute says where the link points.
A link with href
<!DOCTYPE html>
<html>
<body>
<a href="https://www.hyring.com">Visit Hyring</a>
</body>
</html>The src Attribute
The <img> element shows an image, and its src attribute gives the path to the image file.
An image with src
<!DOCTYPE html>
<html>
<body>
<img src="photo.jpg">
</body>
</html>Common Attributes
Guidelines
- Write attribute names in lowercase.
- Wrap attribute values in double quotes.
- Separate multiple attributes with a space.
Note: The style attribute styles a single element inline. It is covered fully in the Styles topic.
Exercise: HTML Attributes
Where in an HTML element are attributes placed?