Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the 'name' attribute considered outdated for <a> anchor tags?

Visual Studio doesn't like on-page anchor tags:

Validation (XHTML 1.0 Transitional): Attribute 'name' is considered outdated. A newer construct is recommended.

I'm using name attributes in this way…

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd" xml:lang="en">
    ...
    <body>
        ...
        <p>On this page&hellip;</p>
        <ul>
            <li><a href="#one">Section One</a></li>
            ...
        </ul>
        ...
        <h2><a name="one">Section One</a></h2>
        ...
    </body>
</html>

Is there really a more-modern way of doing this? Or is Visual Studio full of crap?

like image 399
Zack Peterson Avatar asked Mar 03 '09 21:03

Zack Peterson


People also ask

Is name an attribute of anchor tag?

An anchor name is the value of either the name or id attribute when used in the context of anchors. Anchor names must observe the following rules: Uniqueness: Anchor names must be unique within a document. Anchor names that differ only in case may not appear in the same document.

Why do we use name attribute with anchor tag?

The name attribute is used to create a named anchor. When using named anchors you can create links to a specific section on a page, instead of letting your viewer scroll around to find what he/she is looking for.

Which is correct for anchor tag?

The <a> tag (anchor tag) in HTML is used to create a hyperlink on the webpage. This hyperlink is used to link the webpage to other web pages or some section of the same web page. It's either used to provide an absolute reference or a relative reference as its “href” value.

What is the most important attribute of anchor tag?

The <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination.


1 Answers

You should use the id attribute instead. Works the same way, and you don't need an artifical <a name=...>, but simply

<h2 id="one">Section One</h2>
like image 138
phihag Avatar answered Oct 24 '22 11:10

phihag