Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Content Preparation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Deprecation of the "a" Tag Name Attribute

The name attribute of the "a" (link) tag is not supported in HTML5.

The function of the named anchor is for scrolling to a certain point on a page when a link is clicked. It is used to create a bookmark inside a web page.

Live example: Scroll to bottom of article.

The above link is:

<a href="#bottom_of_article">Scroll to bottom of article.</a>

Near the bottom of the article is the named anchor to be scrolled to:

<a name="bottom_of_article">[point scrolled to]</a>

Optionally, the link text may be absent:

<a name="bottom_of_article"></a>

The in-page bookmarking method is in two parts.

  1. A link with a "#" symbol followed by the value of an "a" tag name attribute. The href contains the #value.

    1. The #value can be by itself as the href value (for same-page bookmark).

    2. Alternatively, the #value can be appended to a URL (for bookmarking a location within a different web page).

    Examples:

    <a href="#value">Link text</a>
    <a href="page.php#value">Link text</a>
    <a href="http://example.com/#value">Link text</a>
    <a href="http://example.com/page.php#value">Link text</a>
    
    
  2. A link with a name value. In this one case, the href tag is optional. Link text is also optional. Examples:

    <a name="value"></a>
    <a href="." name="value">Home page</a>
    
    

The named anchor method for in-page bookmarks will continue to work in browsers for a while. Perhaps for years. The HTML5 specification has not yet been finalized.

Although the named anchor method may be workable for many years, it can't be counted on. For new projects, use the new method, an id attribute instead of a name attribute.

The New In-page Bookmarking Method

The new method is to use the id attribute instead of the name attribute. The id attribute can be in an "a" tag or any other HTML tag that can have an id attribute – div, span, td, pre, etc.

The new method also works in HTML4. So you can start using it now and have it work just fine.

  1. The first part of the in-page bookmarking method is the same for the new method as it is for the named link method (the link at the place to click).

    The first part is an "a" tag with a "#" symbol followed by the value of an id attribute as the a tag's href value. The #value can be by itself or the #value can be appended to a URL. Examples:

    <a href="#value">Link text</a>
    <a href="page.php#value">Link text</a>
    <a href="http://example.com/#value">Link text</a>
    <a href="http://example.com/page.php#value">Link text</a>
    
    
  2. But the second part is different than the first method. Instead of name="value", use id="value". Examples:

    <div id="value1">content</div>
    <span id="value2">content</span>
    <a href="sale.html" id="value3">Link text</a>
    <td id="value4">content</td>
    
    

The id can be the attribute of any HTML tag that can have an id.

Note that id values must be unique on a web page. There can be no two id="here" on the page, for example.

Example Scroll-To Location

The live example "Scroll to bottom of article" link near the beginning of the article scrolls the page to the next paragraph.

[point scrolled to]

Scroll back up to live example of named anchor link.

The above link can be used to scroll back up.

With the a tag name attribute on the way out, it may be prudent to use the id value, instead, for new websites or when redesigning websites. The id value method does work with the current HTML version, HTML4.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC