2

I am using img tag but its not working this is my code

 <img src="resources/images/dsr_sprites.png" ></img>

and I have also use that type

<img src="resources/images/dsr_sprites.png" />

but when I open in firebug that have no close tag and we we use that code for itextpdf its also showing error message that img close tag is missing

Vucko
  • 20,555
  • 10
  • 56
  • 107
Mangita
  • 41
  • 1
  • 5
  • 4
    `` is self closing tag, so your second example is correct. https://developer.mozilla.org/en/docs/Web/HTML/Element/img and look for `Tag omission` – Morpheus Feb 24 '15 at 13:07
  • 1
    error or warning/suggestion. What doctype are you using? – atmd Feb 24 '15 at 13:08
  • 1
    @Morpheus if this is HTML5, neither are correct. `` would be correct. – Jørgen R Feb 24 '15 at 13:09
  • @jurgemaister yes, you are correct, thanks for correction :) – Morpheus Feb 24 '15 at 13:12
  • 2
    @jurgemaister: HTML5 allows the `/>` syntax as a way of accommodating people too used to XHTML syntax, but it doesn't actually mean anything as long as the document is text/html. – BoltClock Feb 24 '15 at 13:16
  • @Morpheus I am already using that but when I create pdf its showing error message that img closing tag is missing – Mangita Feb 24 '15 at 13:17
  • 1
    @BoltClock I am aware that the spec says that it *may* contain a `/`, but it doesn't validate with w3c's validator, and I genrally consider it superfluous. If you want XHTML, write XHTML, otherwise stick to the norm. – Jørgen R Feb 24 '15 at 13:22
  • @jurgemaister: Yeah, no disputing that last bit. But if it's not validating for you, something else is wrong. Out of the scope of this discussion certainly, so I'll stop here. – BoltClock Feb 24 '15 at 13:24
  • 1
    Unless you are writing XML/XHTML then `` is fine; i.e. you do not have to close it at all. – Sverri M. Olsen Feb 24 '15 at 13:51
  • So this question (and error) is only related to **iTextPDF** right? Because self closing or not in HTML both are fine, in XHTML self closing is a must. But what is considered *correct* is iTextPDF is beyond my help. I'd check their documentation regarding this and how to solve it. Maybe the error that you're seeing is not actually the one that's happening. But **first of all I'd make it clear what you're question is**. Is it about iTextPDF problem or HTML problem? – Robert Koritnik Feb 24 '15 at 13:56
  • @RobertKoritnik yes problem with itextPDF – Mangita Mar 03 '15 at 07:33
  • @Mangita - have you ever figure this out? I have a similar problem, where in my code, I close the img tag, bug when I look at the source code of the published webpage, the img tag is not closed (I use both / and ). None of them show up in the code. thanks – Kenneth Browning Nov 20 '20 at 12:41

3 Answers3

1

Img tag is self closing, also on html 5 you can if you want, not closing the tag.

xHtml:

<img src="image.jpg" alt="My image" />

Html5

<img src="image.jpg" alt="My image">

Please dont forget the alt attribute.

Pik_at
  • 1,459
  • 9
  • 14
  • Not closing image tags is for HTML in general (not just HTML5). It is only XHTML that is anal about it (it was based on XML, which is where it comes from). – Sverri M. Olsen Feb 24 '15 at 14:28
0

i think you use this type your image tag:

<img src="../resources/images/dsr_sprites.png" />
Jenti Dabhi
  • 870
  • 5
  • 11
0

It looks like you're using the incorrect path, so your HTML can't find your image anywhere.

The second tag is correct, but your path needs to be relative. Check out this article for more on the difference between absolute and relative paths.

<img src="../resources/images/dsr_sprites.png" alt="Sprites"/>

BDD
  • 665
  • 17
  • 31