All HTML elements can have attributes.
Attributes provide additional information about an element.
They are always specified in the start tag and usually come in name/value pairs.
<tagname attribute_name="value">Content</tagname>
<a href="https://www.example.com">Visit Example</a>
Attribute | Purpose | Example |
---|---|---|
href | Specifies the URL for a link | <a href="https://example.com"> |
src | Specifies the path of an image | <img src="image.jpg"> |
alt | Provides alternate text for an image | <img alt="My Image"> |
The <img>
tag should also include the width and height attributes.
These attributes specify the size of the image in pixels.
<img src="image.jpg" width="300" height="200">
Attribute | Purpose | Example Value |
---|---|---|
width | Specifies the width of the image (in pixels) | 300 |
height | Specifies the height of the image (in pixels) | 200 |
The alt attribute is used with the <img>
tag to specify alternate text for an image.
This text is displayed if the image cannot be shown — for example, due to a broken link, slow internet, or when using a screen reader.
<img src="image.jpg" alt="Description of the image">
Attribute | Purpose | Example Value |
---|---|---|
alt | Alternate text for the image | "A beautiful sunset" |