Value of including slash in image tag


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!


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


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


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


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