1

I'm learning html/css and following the tutorial @ W3Schools.com. The code that I'm having trouble with is @ http://www.w3schools.com/css/tryit.asp?filename=trycss_vertical-align

In line 11

<p>An <img src="w3schools_logo.gif" alt="W3Schools" width="270" height="50" /> image with a default alignment.</p> 

what does the / do just just before the > and after the height attribute? I looked at http://www.w3schools.com/tags/tag_img.asp but it didn't mention /.

user3247608
  • 583
  • 3
  • 9
  • 17
  • That represent the inline `close` tag. You would have seen `

    sdsd

    ` whereas this is just [void tag](http://stackoverflow.com/questions/3558119/are-self-closing-tags-valid-in-html5).
    – Praveen Feb 07 '14 at 07:17
  • possible duplicate of [Are self-closing tags valid in HTML5?](http://stackoverflow.com/questions/3558119/are-self-closing-tags-valid-in-html5) – Praveen Feb 07 '14 at 07:19
  • @Praveen It was my understanding that the html/css tutorials were fine but the javascript ones contained errors. – user3247608 Feb 07 '14 at 07:22

6 Answers6

5

Absolutely nothing, the trailing / is just ignored by the parser.

It is allowed on void tags (i.e. those without other tags/text content inside) by HTML5 specs to make the tag "self-closing", thus the markup valid XML. But it has no HTML-specific meaning.

Conversely, it is compulsory in xHTML for the same reason (making the markup valid XML).

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
1

In HTML there are two kind of tag :

First, e.g <div> that you need to close like </div> because it can have other tag inside

Second, e.g <img/> <br/> that doesn't need </img> or </br> to close. These are called void tags means it can't contains other tags.

Manish Kumar
  • 10,214
  • 25
  • 77
  • 147
1

The "/" is basically used for ending tags. In HTML you need to start your tag and you need to end your tag the code here<img marks the opening of the tag so you need to close it with />

Rohan
  • 673
  • 6
  • 15
0

/> is required for ending HTML tags which don't have a closing tag . They are required to make tags compliant with XHTML. Other examples are <br/> <hr/>

Mudassir Hasan
  • 28,083
  • 20
  • 99
  • 133
0

in HTML, elements have a beginning and ending tag e.g. <p> & </p> and in between these beginning and ending tags come the content of that element.

But some elements do not have content e.g. <br /> for line break and <img src="" /> for images. Such Elements are called empty elements and do not need a closing tag separately. Hence, the /> denotes closing of this tag.

Saeedses
  • 109
  • 1
  • 1
  • 8
0

in html each end every tag has an opening and closing like for body tag, the syntax is like <body></body>

similarly for imagae tag its like <img></img>

But we can use the other short form also...which is we are marking the closing option also with the same img tag... <img/> and then we can give all the options (properties for the img tag) inside it . src="w3schools_logo.gif" alt="W3Schools" width="270" height="50"

so it should be finally like <img src="w3schools_logo.gif" alt="W3Schools" width="270" height="50" />

TKV
  • 2,533
  • 11
  • 43
  • 56