glennda Posted November 30, 2011 Posted November 30, 2011 BBC News - 7 questions on computer programs Question 7 What is the correct HTML 4 for inserting an image? I'm pretty sure its answer 1 not 3 you have to close it! W3 schools doesn't say you don't have to add the / before the > HTML img tag maybe somebody should have taught that person html at school!
MrEprise Posted December 1, 2011 Posted December 1, 2011 Just tested this, either way seems to work fine.
ZeroHour Posted December 1, 2011 Posted December 1, 2011 W3C says you dont in their own example: The IMG (Image) Element I never close img tags using a /
Arthur Posted December 1, 2011 Posted December 1, 2011 (edited) you have to close it! W3 schools doesn't say you don't have to add the / before the > I think you are getting confused with XHTML which did require a forward-slash to be compliant. XHTML, an implementation HTML serialized as XML. XML has a very strict set of syntax requirements. One of those requirements is that you can't leave a tag open. The syntax is called a self-closing tag, in that it opens itself and closes itself at once. One of the more interesting things about XHTML is that it's kind of backwards compatible with HTML. You can throw a legal XHTML document at an HTML parser and it should be able to make sense out of it. However, not all HTML parsers can do so. Old, old, prehistoric, no-longer-used versions of Netscape and other browsers would see the self-closed tag not as a br, but as a tag named br/, which is bogus. Putting a space before the forward slash became best practice. There's a fatal flaw with XHTML. Because it requires the XML parsing rules, that also means it requires the XML error handling rules, which mandate that parsing halt immediately upon a syntax error. In other words, if there's a single parse error in the document, the browser must not show the document to the user. That's kind of a show-stopper. XHTML served as XML never caught on because some browser vendors (like Microsoft) refused to add support due to the must-die-immediately nature of error handling. XHTML still caught on because it was full of awesome best practices, even if the documents didn't end up being served as XML. Now, earlier I said that you don't need it any longer. That is true for both HTML4 and the upcoming HTML5. They've gone through the effort of actually specifying how HTML5 should be parsed now, and that forward slash is going to be considered an error. Thankfully XHTML5 is a thing, and if you really want to use the XML syntax rules instead of the HTML5 syntax rules, you can go right ahead. (Source) XHTML uses an XML syntax, while HTML uses a pseudo-SGML syntax (officially SGML for HTML 4 and under, but never in practice, and standardised away from SGML in HTML5). Secondly however, because the expressible contents of the DOM in syntax are slightly different, there are some changes in actual behavior between the two models. Firstly then, syntax differences: Broadly, the XML rules require that all elements be closed, either by a separate closing tag or using self closing syntax (e.g. ), while HTML syntax permits some elements to be unclosed because either they are always empty (e.g. ) or their end can be determined implicitly ("omissibility", e.g. ). (Source) See also: wiki.whatwg.org/wiki/HTML_vs._XHTML#Syntax_and_Parsing W3 schools doesn't say you don't have to add the / before the > It does... In HTML the tag has no end tag. In XHTML the tag must be properly closed. I'm pretty sure its answer 1 not 3 For HTML4 and HTML5, it is definitely answer 3. I think you owe the BBC an apology. Edited December 1, 2011 by Arthur
philwaud Posted December 1, 2011 Posted December 1, 2011 I did this yesterday and got the film one wrong! Today, some of the questions have different answers so there must be a randomiser built in. The correct tag for an image is To be XML compliant, any tags that dont have a closing tag should be closed with a /> at the end, but thats irrelevant as its the IMG and IMAGE that are the key points.
Arthur Posted December 1, 2011 Posted December 1, 2011 Another site that's worth mentioning is W3Fools. The aim of this website is to correct all of the errors and bad advice given on W3Schools. We are passionate about the web, learning, and craftsmanship. We want you, as web designers and developers, to be successful in your careers. We feel, though, that W3Schools is harming the community with inaccurate information. Like any other authoritative educational resource, W3Schools should both hold itself to, and be held to, the highest standards. We hope we can illuminate why W3Schools is a troublesome resource, why their faulty information is a detriment to the web, and what you (and they) can do about it.
philwaud Posted December 1, 2011 Posted December 1, 2011 Did exactly the same thing myself, had the same argument (with myself!), and then spotted the IMAGE bit! Phil
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now