View Full Version : XHTML Anchors

04-30-2008, 11:47 AM
Hi Ive been using the following code to make anchors for my site:

<a name="top"></a>

Can someone please tell me an XHTML alternative to this?

Thanks for your help.

04-30-2008, 12:18 PM
I don't think there are two types of anchors, one for html and other for xHTML!
Oh.. are you asking about name attribute? You could use id there.

04-30-2008, 01:24 PM
Any element can be an anchor through the id attribute. The name attribute is deprecated for all elements except form controls. So, you could have something like:

<a href="#anchor">anchor</a>

<h1 id="anchor">Headline</a>
<p id="anchor">Text</p>
<div id="anchor">Section</div>
<div>Lorem ipsum dolor sit amet, <a id="anchor">consectetuer</a> adipiscing elit, sed diam…</div>

The anchor link will jump to whatever element has the appropriate ID. But note that an ID must be unique on a page. The example above is just to demonstrate the ID attribute in various situations.

04-30-2008, 04:28 PM
If you're just looking for the XHTML-valid version of it, you've got it right there. Always make sure your attributes are enclosed in quotes and all tags are closed with the slash /...

<br/> or <a name="..."></a>

I use that style on my XHTML Transitional site, and it works fine with validation.