Attributes
You can have more control over html elements with attributes.
Attributes are modifiers that provide additional information about elements.
Attributes can be optional or required.
Required attributes:
The
<img>
tag requires an attribute src to work correctly.The anchor tag requires href to work correctly.
For container tags the attribute always go in the opening tag.
It is best practice to describe what images are showing. The alt attribute, (alternative text) is used to add an image description.
The alt attribute can be:
read aloud by screen readers.
shown when the image doesn’t load.
read by search engines.
You can control the size of images in your webpage. width is an optional attribute.
Both width and height are measured in pixels by default.
When only two attributes are given, the browser will calculate the other based on the aspect ratio, so the image is not stretched or squeezed.