Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to mix links ( <a> tag ) and headings ( <h1> tag ) in web standard?

What is the correct code to create a link with heading 1 according to web standards?

is it

<h1><a href="http://stackoverflow.com"> stackoverflow </a></h1> 

or

<a href="http://stackoverflow.com"><h1> stackoverflow </h1></a> 

Thanks

like image 785
ahmed Avatar asked Jul 15 '09 00:07

ahmed


People also ask

Can I have multiple H1 tags on a page?

It is common to have multiple H1 heading tags in different parts of your page, in your website's template, theme or other sections. Regardless of whether you use HTML5 or not, having multiple H1 elements or multiple heading tags of the same type on a page is completely fine.

Can H1 be inside a tag?

According to web standards you aren't allowed to put block elements into inline elements. However, there is an exception that in HTML5 it is valid to wrap block-level elements (like div , p or h* ) in anchor tags.

How do I add a link to my H tag?

To make a hyperlink in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink. Add the URL for the link in the <a href=” ”>.


1 Answers

According to web standards you aren't allowed to put block elements into inline elements.

As h1 is a block element and a is an inline element the correct way is:

<h1><a href="#">This is a title</a></h1> 

Here is a link so you can learn more: w3 Visual formatting model

However, there is an exception that in HTML5 it is valid to wrap block-level elements (like div, p or h*) in anchor tags. Wrapping block-level elements in inline elements other than anchors still goes against the standards.

like image 95
Darko Z Avatar answered Sep 30 '22 05:09

Darko Z