Value of including slash in image tag


#1

Hi everyone,

Haven't used HTML/CSS in a few years so I thought I'd take this class to review and then do the interactive one. As when I learned the first time XHTML wasn't covered, I was expecting to have to look this up eventually, but thought the answer would be more clear-cut by now...

In the image lesson the img tag example looks like:

<img src="[image url]"/>

There is a forward-slash there and I wanted to know if this is still being advised. I have read the stackoverflow and old Codecademy forum topics on the subject; the general consensus seems to be to exclude it. However, almost everything I saw is a couple years old, so I was wondering if things have changed since.

Thanks all!
frisby


https://www.codecademy.com/en/courses/make-a-website/lessons/site-structure/exercises/add-image?action=resume


#2

it is xml/xhtml syntax, so if you are writing xml you will need the slash. But most of the time you will use html, then the slash is not required:

<img src="imageurl">

will do just fine


#3

Thanks, @stetim94! Most of the old forum answers I read were yours, too :smile:

Before I started researching I thought (since several years ago) that I would have to learn XHTML the next time I used HTML again, but now it seems like the winds have changed. :slight_smile: lucky me


#4

yea, few years ago things where different. now we use html5, which is really good


#5

Oh good, I'm glad I waited then. Even if that means I'm a "polo-necked frameless-spectacle wearing graphic designer" :joy: