4 ms·
Ask HN: What's wrong with the HTML in this line?
A friend of mine had to take a test for a job as a TV presenter that, strangely, had some HTML questions on it. I guess the station has decided that everyone needs to know something about the web.
Anyway, one of them was "what's wrong with the HTML in this line:"
<p>(<a href="http://www.amazon.com/Flip-MinoHD-Camcorder-Minutes-Black/dp/B001HSOFI2" target="_blank">Amazon.com</a>)</p>
As far as I can tell, there is NOTHING wrong with that line. But am I missing something obvious?
- maxdemarzi 17y agoMaybe it's not a technical question, but a logical question. It's a direct to product link labeled as a company link?
- RiderOfGiraffes 17y agoI regard this as a chance to learn something about the technical details of HTML, so my answer whould not be regarded as definitive. Or even correct. However ... It depends on the variant of HTML, but surely "<p>" is not a, what's the technical term, container? In the variants of HTML that use <p> you don't then have to have a </p> because it's not of the open/close variety.
- mooism2 17y ago"Block element"? Yes it is. The "</p>" is optional, not banned.
- RiderOfGiraffes 17y agoOK, thanks. In what variants? And is it regarded as "Good Style" (whatever that might mean)
- mcav 17y agoIn XHTML, the </p> is required. In HTML, some people prefer to close all tags for cleanliness; others prefer to leave the <p> open. It's really a personal preference. Personally, I like the more minimal approach of leaving the closing tag out (one less thing to try to match up). Others like it to look like XML (everything closed). As far as the original post's question -- that HTML snippet is perfectly fine.
- TeHCrAzY 17y agoI find unclosed tags to be ambiguous, hard to format, and that they lead to more errors, I'd be interested to see why you prefer working with the opposite, personal preference aside.
- mcav 17y agoI don't leave every tag open; just a few: tr, td, p, li. To me, it's intuitive that when the next row/listitem/paragraph begins, the first one ends. So I think this is perfectly readable: <ul> <li>Item1 <li>Item2 <li>Item3 </ul> <table> <tr> <td>Foo <td>Bar <td>Baz <tr> <td>Foo <td>Bar <td>Baz </table>
- mooism2 17y agoThey may be objecting to use of target, which isn't allowed in html 4 strict as far as I remember. But if they're expecting TV presenters to hand-write html, that's a bit picky.