Self-closing tags


#1

Re: self-closing tags-when you say nothing goes between the tags or tags, what do you mean please. there's a lot between the tags. sorry to be obtuse


Replace this line with your code.


#2

Self-closing tags are a single set of tags, that end with />

For example img tags are self closing:

<img src="https://s3.amazonaws.com/codecademy-images/discuss_cc-logo.png" />

Whereas p tags aren't self closing:

<p> Text </p>

#3

<p>something in between the tags</p>

This tag is not self-closing since it contains something between the tags. A self-closing tag is one which does not make up a container, but a simple object. It may have attributes, however. Attributes are object properties, not content.

<img src="image.png" alt="alternate text" width="100" height="100">

(In HTML5, we may write the tags just as we would in HTML 4, without the / at the end.)

Notice above that the IMG element has four properties (attributes):

src
alt
width
height

You may read about these being referred to as void elements. This speaks to them not being containers.

With regard to the /. It is a spill over from XHTML which is XML conforming. HTML5 may be written and served as text/html, the slash is not needed, or as application/xml in which the slash is required. XHTML is insistent upon there being a space before the slash, but HTML5 is not.

<img>
<img/>
<img />

All three are valid HTML5. Some might say it is good practice to include them, but I say why bother if we don't understand their meaning and our document is text/html? Don't let anybody tell you that we must include them. That would be misleading.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.