Why are some tags self-closing (img, br, etc.) whereas others are not?
Answer
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!
If we need to define a content in terms of itās START - END then, besides the start point we have to declare also the end point.
e.g.
We declare a title, then we have start & end point for it, <title></title>
We write a paragraph just for others to see, then we use <p> and close it with </p>
We declare a specific piece of this text for e.g. to be in French. We then use<span> & close it as </span>
We declare some words to be in bold or italics, again we have start & end of the text we want to format, so <strong> & </strong><em> & </em>
We group elements, again we need to declare which items are to be grouped together. So again, we have an open close case <div></div>. Same when we create lists, ordered or unordered ones.
Whereas,
We insert a line break in a specific point, so we say <br> once. A line break is going to be formatted, without any other need.
We insert an image in a specific point, so we say <img> once. Again, thereās no need to close anything, as we say <br> and <img> are self-closing tags.
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!
Any content between the opening and closing <video> tags is fallback content . This content is displayed only by browsers that donāt support the <video> tag.
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.
Certain errors in HTML can run normally as the browser will render correctly (it corrects your code)
In the case of a hyperlink if you donāt close it then the rest of the elements until thereās an end point (could be another hyperlink) will also be wrapped in the hyperlink.