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
  • 515
  • 2
  • 8
  • 15
  • 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
  • You should [accept an answer](https://meta.stackexchange.com/questions/16721/how-does-accept-rate-work/65088#65088) if you consider your problem solved. – Stefano Sanfilippo Jun 11 '14 at 09:46

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
  • 29,175
  • 7
  • 71
  • 78
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
  • 9,298
  • 16
  • 72
  • 128
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
  • 613
  • 5
  • 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
  • 26,105
  • 18
  • 90
  • 124
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
  • 99
  • 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,325
  • 9
  • 39
  • 54