0

Possible Duplicate:
Can we place `<img>` inside `<h1>` according to web standards?

I would like to add a small image to appear at the end of every H1 header, the easiest way would be to create the image and simply

<h1>Title <img src="image.png" ></h1>

I do not want to use a background image because I want the image to be positioned at the end of the h1 title, which means that it will vary and a background can only be fixed.

Is having an img tag within a header tag invalid code in any html standards?

I ran this through W3 markup validation with HTML5:

<h1>Hello <img src="smiley.gif" alt="Smiley face" height="42" width="42"></h1>

and I get the following error:

Line 1, Column 19: Element head is missing a required instance of child element title.

Anyone know what that means?

Community
  • 1
  • 1
user1945912
  • 597
  • 3
  • 9
  • 19
  • You need to supply a complete html document to the validator. Starting with doctype, html, head (including title) and then your h1 and img tags inside the body. – hsan Feb 01 '13 at 22:36

3 Answers3

3

let your page validate from w3c, they will tell you. http://validator.w3.org/

Eveli
  • 498
  • 1
  • 6
  • 27
3

According to MDN the content of an <h1> tag should be "phrasing content", which includes <img> tags as well.

On the other hand you could use the CSS-style background-position to align the background image like you want:

background-image: url( image.png );
background-position: right;
Sirko
  • 72,589
  • 19
  • 149
  • 183
2

I don't think this is invalid but as suggested by @Ekonion w3.org is a correct option to check it.

Apart from this, you can also use css background-position to position your image in the background as per your requirement. Just an alternate anyway :)

Hope it helps.

Anmol Saraf
  • 15,075
  • 10
  • 50
  • 60