I haven't done serious web dev since 2013. I was usually pretty conscious of best practice. Lately as I'm using templates I'm seeing alot of <img src=""...>
instead of <img />
such as I had learned. Did something change? Is best practice changed?
Asked
Active
Viewed 176 times
1

Leo Blanchette
- 43
- 3
-
Is the spec you're following HTML or XHTML? – Enigmativity Feb 15 '20 at 04:56
-
See https://stackoverflow.com/questions/1946426/html-5-is-it-br-br-or-br – Feb 15 '20 at 04:57
-
See also https://stackoverflow.com/questions/14860492/how-to-close-img-tag-properly/14860541 – Feb 15 '20 at 04:58
-
I believe this question may be a duplicate of the two questions I just cited. Also https://stackoverflow.com/questions/23890716/why-is-the-img-tag-not-closed-in-html Many answers are quite old, but still valid; there are also many newer answers. – Feb 15 '20 at 04:59
-
There's no absolute answer to this question. `
` is acceptable according to specs. `
` is more readable and conveys intention more clearly for somebody who's not proficient in HTML. – yqlim Feb 15 '20 at 05:01
-
https://stackoverflow.com/questions/4693939/self-closing-tags-void-elements-in-html5 – ksav Feb 15 '20 at 05:03
1 Answers
2
In HTML (up to HTML 4): use <br>
In HTML 5: <br>
is preferred, but <br/>
and <br />
is also acceptable
In XHTML: <br />
is preferred. Can also use <br/>
or <br></br>
Notes:
<br></br>
is not valid in HTML 5, it will be thought of as two line breaks.- XHTML is case sensitive, HTML is not case sensitive.
- For backward compatibility, some old browsers would parse XHTML as
HTML and fail on
but not
Reference:

Malakiya sanjay
- 208
- 2
- 12
-
-
In XHTML `
` is mandatory. `
` and `
` are just alternative ways of writing the same thing. – Enigmativity Feb 17 '20 at 21:16