Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a <small> tag be inside an HTML5 heading (i.e. h1, h2, h3, etc...)?

Tags:

I'm not sure about the convention regarding headings in HTML5, but I wanted to know if I could add a <small> in a <h3>, like this (this could apply to any tag inside any heading tags):

<h3>Payment details <small>(this is your default card)</small></h3> 
like image 261
Shaoz Avatar asked May 05 '11 08:05

Shaoz


People also ask

Which tag is used for small heading in HTML?

HTML <small> Tag.

What are h1 H2 H3 tags in HTML?

HTML defines six levels of headings. A heading element implies all the font changes, paragraph breaks before and after, and any white space necessary to render the heading. The heading elements are H1, H2, H3, H4, H5, and H6 with H1 being the highest (or most important) level and H6 the least.

What are h1 H2 and H3 headings?

In simple terms: Heading tags are HTML elements used to define the headings of a page. They differentiate the heading <h1> and sub-headings <h2> to <h6> from the rest of the content. The number from 1 to 6 determines the importance and the position a heading has in the overall hierarchy of the heading structure.

Is h1 the smallest heading?

h1 is the highest heading level (and, by default, the largest in terms of font size) and h6 the lowest (and smallest).


2 Answers

Yes, that markup validates. You can check it yourself on http://validator.w3.org/

Something to be aware of with HTML5 though is a change to the notion of block-level elements: https://developer.mozilla.org/en/HTML/Block-level_elements

like image 130
Ian Oxley Avatar answered Oct 07 '22 05:10

Ian Oxley


The specs for heading elements:

  • http://dev.w3.org/html5/spec/the-h1-h2-h3-h4-h5-and-h6-elements.html#the-h1-h2-h3-h4-h5-and-h6-elements

says that it has phasing content model:

Content model:     Phrasing content. 

Looking at the part of the specs for phasing content model:

  • http://dev.w3.org/html5/spec/content-models.html#phrasing-content

It says this:

Note: Most elements that are categorized as phrasing content can only contain elements that are themselves categorized as phrasing content, not any flow content.

Aside from this, you cannot put heading in another heading - this is from W3C validator:

Error Line 1, Column 23: Heading cannot be a child of another heading.  <!DOCTYPE html><h1><h2></h2></h1> 

Although I could not find in the specs where it explicitly says this, there are restrictions that seem rather specific. This can yield to some very odd behavior such as that the above HTML would actually be parsed as

<h1></h1><h2></h2> 

e.g. see this SOq for an example of indirect issues it can cause:

  • Show hidden element inside another element on click

Just in case someone runs into this...

like image 33
icyrock.com Avatar answered Oct 07 '22 05:10

icyrock.com