Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Wisnu Mulya
Wisnu Mulya
15,938 Points

Anchor element without href attribute

Is there any use of using an anchor element without an href attribute?

4 Answers

According to W3.org a - hyperlink the anchor element is almost always used with href attribute. The only example given on the above page is that of a placeholder anchor. A placeholder anchor is one in which the href has been omitted. Prior to HTML5 you could use the name attribute in conjunction with an anchor element but this has been deprecated. If you want to still perform in-page link you would use the id attribute with different elements and the use the anchor element with the href attribute to link to the id in page.

Unfortunately, No. It is mainly used to link another document, other part of a document and create a relationship between documents.

Why do you want an anchor element without an href attribute? What is the purpose?

Wisnu Mulya
Wisnu Mulya
15,938 Points

In the CSS deep dive, Guil said that link pseudo-class will only select an anchor element with an href attribute. I was just wondering is there any anchor element without an href attribute. And if so, what is it for. Anyway, Gary Bates has made a clear point to me.

Hi, Actually I never heard about anchor elements without href attribute, the anchor tags or anchor elements using href is globally used to link any pages or elements each other, except you're using tabs or accordion for showing your contents in different places, then you only need javascript, your contents will be loaded all for once and splitted as tabs or accordions depends on which one you used.