Why are some tags self-closing (img, br, etc.) whereas others are not?
The important distinction between self-closing tags and all other tags is that self-closing tags represent void elements. Void elements like img and br cannot contain any content. All other tags may (but are not required to) contain content.
Content is defined I believe on the second slide of this section as “information between the opening and closing tag.” This does not include attributes (like alt) which are solely defined within the opening tag!
So when it says “self-closing tags represent void elements […] like img and br cannot contain any content”. I’m slightly confused because isn’t the alt attribute in the img element in a way, content? It’s just not seen on the screen? Because it can be heard, right?
Lastly, if that’s the case, I also just wanted to know how videos contain content, and how that differs from the alt attribute…
I hope I’m kind of making sense here. This question took some time to put into words.
You’re confusing what ‘content’ means in HTML.
With any HTML tag the ‘content’ is what appears between the opening and closing tag: <openingTag>content</closingTag>
For example: <p>Some random text.</p> <img> is called self closing because there is no closing tag with content in the middle.
In this example: <img src="myHouse.gif" alt="My House"> src and alt are attributes that have values assigned, but neither is referred to as ‘content’.
Hope this helps!
yes, in the HTML DOCUMENT STANDARDS when they were talking about making an image clickable.
the exercice was about, (transform the image on your page into a link by wrapping the image element with an anchor element.)
and that’s exactly what i did, but i forget about the closing anchor ( < /a > )
but it worked anyway, without the closing anchor, so i just want to know why.