Why are some tags self-closing but others are not?


#1

Question

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.


FAQ: Learn HTML Elements - Intro to HTML - Videos
#2

What does the abbreviation ‘src’ stand for?


#3

It stands for “Source”, as in the location in which the file is located. In this situation the local or web address in which the image is located.


#4

img and br cannot contain any content,
we can see"A field of yellow sunflowers"in No.14, It’s content!


#5

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!


#6

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.

  1. We declare a title, then we have start & end point for it, <title> </title>
  2. We write a paragraph just for others to see, then we use <p> and close it with </p>
  3. We declare a specific piece of this text for e.g. to be in French. We then use<span> & close it as </span>
  4. 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>
  5. 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,

  1. 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.
  2. 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.

#7

It makes sense, what is confusing is that we insert a video in a specific point, so we should say <video> once, but we have to close it instead. :frowning:


#8

wow, it is easy standard for recognizing those two!


#9

Every rule have it’s exceptions :slight_smile: