marcus
marcus

Reputation: 10086

Is it ok to create anchors without href attributes?

If you take this example, <a name="xxx"></a> ... is this ok when creating an anchor? I have always preferred to use an already created tag for my destinations.

Upvotes: 2

Views: 3357

Answers (4)

Sadesh Kumar N
Sadesh Kumar N

Reputation: 2052

Using an anchor tag without href is useless. It is simply put a text styling to the contents inside the tag. But you can use a anchor tag without a href, But onthe onclcick event you can dynamically divert the navigation of page. We use simply in some sites to apply the style to the contents within the anchor tag.

Upvotes: 0

matpol
matpol

Reputation: 3074

If you are using this for in page navigation you can just just the id of the element rather than having to set up the anchor tag e.g.

<a href="#stuff">link to stuff</a>

<div id="stuff"></div>

I personally would not use an empty anchor tag.

Upvotes: 11

Sergei
Sergei

Reputation: 2757

Of course, why not? You just create internal link to content block with this method.

Upvotes: 1

Wim
Wim

Reputation: 12082

For navigational purposes within one page, it's perfectly fine. Though that style of navigation is usually related to some kind of headings or titles, so usually most people end up surrounding the appropriate heading/title with the anchor. I guess it's better from a readability and maintenance point of view.

Upvotes: 3

Related Questions