Sunday, 19 February 2017

html - Do I need a "/" at the end of an or tag, etc.?




Do you need to have a / at the end of an img tag? I saw an example on W3schools.com without a /:



Smiley face


I know it isn't necessary to self-close the tag, at least in my browser, but should I do so?


Answer



The / is only required for XHTML & XML.



If you're using a HTML5 doctype, then there's no need to terminate self-closing tags in this way.



This applies to ,
,


etc.



I.e. Just use ,
and


.



If you need an empty element (like a div), don't use

, instead use
. This is important since in HTML5, the slash is ignored and
is interpreted as
without a closing tag.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...