Skip to content

Commit a5d7017

Browse files
authored
Clarify new optionality of src if srcset is available. (#39557)
* Clarify new optionality of `src` if `srcset` is available. * Fix typo.
1 parent 7ea5e6b commit a5d7017

File tree

1 file changed

+2
-2
lines changed
  • files/en-us/web/html/reference/elements/img

1 file changed

+2
-2
lines changed

files/en-us/web/html/reference/elements/img/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The **`<img>`** [HTML](/en-US/docs/Web/HTML) element embeds an image into the do
2626

2727
The above example shows usage of the `<img>` element:
2828

29-
- The `src` attribute is **required**, and contains the path to the image you want to embed.
29+
- The `src` attribute holds the path to the image you want to embed. It is not mandatory if the [srcset](/en-US/docs/Web/API/HTMLImageElement/srcset) attribute is available. However, at least one of the `src` or `srcset` attributes must be provided.
3030
- The `alt` attribute holds a textual replacement for the image, which is mandatory and **incredibly useful** for accessibility — screen readers read the attribute value out to their users so they know what the image means. Alt text is also displayed on the page if the image can't be loaded for some reason: for example, network errors, content blocking, or link rot.
3131

3232
There are many other attributes to achieve various purposes:
@@ -61,7 +61,7 @@ SVG remains the recommended format for images that must be drawn accurately at d
6161

6262
If an error occurs while loading or rendering an image, and an `onerror` event handler has been set for the {{domxref("HTMLElement/error_event", "error")}} event, that event handler will get called. This can happen in several situations, including:
6363

64-
- The `src` attribute is empty (`""`) or `null`.
64+
- The `src` or `srcset` attributes are empty (`""`) or `null`.
6565
- The `src` {{glossary("URL")}} is the same as the URL of the page the user is currently on.
6666
- The image is corrupted in some way that prevents it from being loaded.
6767
- The image's metadata is corrupted in such a way that it's impossible to retrieve its dimensions, and no dimensions were specified in the `<img>` element's attributes.

0 commit comments

Comments
 (0)