hfsyria
hfsyria

Reputation: 95

Is it valid to put h2 tag in span tag?

Is it valid to put h2 tag in span tag given that the span tag is displayed as block?
would it make difference for search engines (SEO) if i used div instead

Upvotes: 4

Views: 7512

Answers (3)

Alex W
Alex W

Reputation: 38253

In HTML4, it is not valid to put any block element inside of any inline element.

This changes in HTML5, where it is valid to put block-level elements inside of anchor tags.

Upvotes: 0

Alexey Ivanov
Alexey Ivanov

Reputation: 8236

No, you can't. Accordind to HTML 4.01/XHTML 1.0 dtd you can include only inline elements in span tag. It's the following one:

a, object, applet, img, map, iframe, br, span, bdo, tt, i, b, u, s, strike, big, small, font, basefont, sub, sup, em, strong, dfn, code, q, samp, kbd, var, cite, abbr, acronym, input, select, textarea, label, button, ins, del, script.

Can't quickly check HTML 5, but don't think it's different here.

Upvotes: 2

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 341003

Sample input:

<!DOCTYPE HTML>
<html>
    <head><title></title></head>
<body>
    <span style="display: block">
        <h2>A</h2>
    </span>
</body>
</html>

And results from W3C validator:

Element h2 not allowed as child of element span in this context.

Upvotes: 9

Related Questions