Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In HTML which way round should <a/> and <h1/> be nested?

Tags:

html

xhtml

Is there a more correct order for nesting a <a> and <h1> elements in HTML?

e.g.:

<a href="www.example.com"><h1>Example!</h1></a>

or

<h1><a href="www.example.com">Example!</a></h1>
like image 378
Armand Avatar asked Feb 22 '11 15:02

Armand


People also ask

What is nesting in HTML with example?

It is often necessary to code certain tags (and their text) within the definition of other tags (between the start and end tags). This is called nesting. A good example of nesting is the relationship between the DL (definition list) tag, the DT (definition term) tag, and the DD (definition description) tag.

What is H1 and H2 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.

Can I put an H1 inside of span?

Yes, it's typically fine to use a span inside of an h1 . span is an inline element, so it's typically okay to use it inside anything (that allows elements inside it!)


2 Answers

In HTML 4.01 and XHTML 1.1 and older:

  • An h1 may contain an a
  • An a may not contain an h1

So <h1><a>…</a></h1>

In the HTML 5 draft:

  • An h1 may contain an a
  • An a may contain an h1 (but only if the a is somewhere an h1 is allowed — see the comments on this answer)

So either, but browser support may vary (such is life on the bleeding edge).

like image 99
Quentin Avatar answered Oct 19 '22 05:10

Quentin


this is the right answer:

<h1><a href="www.example.com">Example!</a></h1>
like image 34
JAiro Avatar answered Oct 19 '22 06:10

JAiro