Can I ask why it is optional to add an '/' in img tag in html? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can I ask why it is optional to add an '/' in img tag in html?

25th Dec 2020, 9:26 PM
Someones
Someones - avatar
3 Answers
+ 1
I think to avoid development issues
25th Dec 2020, 9:28 PM
Believe
Believe - avatar
+ 4
For self-closing tag it is optional in modern HTML syntax.But good habits is to close what is opened in tags that contain elements or other HTML inner element inside it but for img will not have other element or content inside it except img URL
25th Dec 2020, 11:22 PM
HBhZ_C
HBhZ_C - avatar
+ 3
You must be talking about how relative URL's don't need a /. If an image is in the same directory as the HTML, a / is unnecessary. Relative paths are interpreted in the context of the current page's URL. If "/" is nowhere in a URL, it is assumed to be in the same protocol, host, and path as the page that mentions it.
25th Dec 2020, 9:35 PM
Josh Greig
Josh Greig - avatar