Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why appear <p> tag around <img> tag?

Tags:

html

css

I have this:

<p>
    <img src="media/icons/info_ticket.png"></img>
    <h3>Ticket #TKMA<span><?php echo $_GET['CRy3sjzZOJyXE']; ?></span></h3>
</p>

And when I apply CSS to change the style of the img it doesn't work! So, I inspected the element and I found this:

<p>
    <img src="media/icons/info_ticket.png">
</p>
<h3>Ticket #TKMA<span>17</span></h3>
<p></p>

I don't understand why this happens.

like image 609
SoldierCorp Avatar asked Feb 15 '13 19:02

SoldierCorp


2 Answers

Because your HTML is invalid. <p> elements can only contain phrasing content.

See List of HTML5 elements that can be nested inside P element?

like image 52
Matt Ball Avatar answered Oct 09 '22 09:10

Matt Ball


The reason is because, an H element inside a <p> element isn't valid so the browser corrects it by pulling it out.

like image 22
Dennis Rongo Avatar answered Oct 09 '22 08:10

Dennis Rongo