H1 in a P?

I keep getting a validator error;

Where an H1 cannot be placed in a P, I know that
P is a block element but Im unsure about H1.

Do I have to keep the H1 outside of the P?
Or can I make H1 display as a non-block element to
embed it inside the P?



You will want to keep the


tag out of the


tags :slight_smile:


H1 is a block element like P, but H1 and P can only have inline content inside of them, unlike other block elements like forms and divs. Therefore, you can’t nest headings inside paragraphs (and if you think about it a heading really should never be in a paragraph).

Thanks :slight_smile:

Yeah now that I think of it like that, very true!
I was just a little flustered how Ill place it where I want
it, but I then realized… Oh yeah, I can style an H1 margin :smiley:

You can make an H1 generate an inline box instead of a block box:

h1 {display:inline}

That does not allow you to embed an H1 inside a P, though. The ‘display’ property only controls what sort of box is generated, it doesn’t change the semantics. The rules governing which elements may contain which are laid down in the HTML DTD (Document Type Definition) and cannot be changed.

You can paint a car to look like a cow, but don’t expect to get much milk out of it. :wink: