Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 50555 of Using the link role

  • Revision slug: Accessibility/ARIA/ARIA_Techniques/Using_the_link_role
  • Revision title: Using the link role
  • Revision id: 50555
  • Created:
  • Creator: hhillen
  • Is current revision? No
  • Comment page created, 494 words added

Revision Content

Description

This technique demonstrates how to use the link role and describes the effect it has on browsers and assistive technology.

The link role is used to identify an element that creates a hyperlink to a resource that is in the application or external. When this role is added to an element, tab can be used to change focus to the link, and space or enter used to execute the link.

The tabindex attribute may optionally be used with this role to directly specify the position of the element in the tab order.

Possible effects on user agents and assistive technology 

When the link role is added to an element, or such an element becomes visible, the user agent should do the following:

  • Expose the element as having a link role in the operating system's accessibility API.
  • Fire an accessible link event using the operating system's accessibility API if it supports it.

Assistive technology products should listen for such an event and notify the user accordingly:

  • Screen readers should announce the text of the link or its label when it is focused, along with the fact that it is a link. ARIA links should be included in the screen reader's “List Links” function just like ordinary links, and actions in this dialogue list, such as “Activate Link” or “Move to Link”, should perform the same as they do with ordinary links. 
  • Screen magnifiers may enlarge links.

 

Note: Opinons may differ on how assistive technology should handle this technique. The information provided above is one of those opinions and therefore not normative.

Examples

Example 1: Adding the role in the HTML code

The snippet below shows how the link role is added directly into the html source code. 

<div role=”link”>A link</div>

Example 2: Accessible link build from an application using span

<script type="text/javascript">
sap = {ui:{keycodes:{SPACE:32, ENTER:13 }}};
//handles clicks and keydowns on the link
function navigateLink(evt) {
    if (evt.type=="click" ||
        evt.keyCode == sap.ui.keycodes.SPACE ||
        evt.keyCode == sap.ui.keycodes.ENTER) {
        var ref = evt.target != null ? evt.target : evt.srcElement;
        if (ref) window.open(ref.getAttribute("href"),"_blank");
    }
}
</script>

<body role="application">

    <h3>Simple Link build with a span</h3>
    <span href="https://www.w3c.org" onkeydown="navigateLink(event)" onclick="navigateLink(event)" tabindex="0" id="link1" role="link" class="link">Activate this link using the space bar or enter key</span><br />

</body>

Working Examples:

Notes 

If pressing the link triggers an action but does not change browser focus or navigate to a new page, you might wish to consider using the button role instead of the link role.

ARIA attributes used

Related ARIA techniques 

Compatibility

TBD: Add support information for common UA and AT product combinations

Additional resources

Revision Source

<h3>Description</h3>
<p class="p1">This technique demonstrates how to use the <a class=" external" href="https://www.w3.org/TR/wai-aria/roles#link">link</a> role and describes the effect it has on browsers and assistive technology.</p>
<p class="p1">The link role is used to identify an element that creates a hyperlink to a resource that is in the application or external. When this role is added to an element, tab can be used to change focus to the link, and space or enter used to execute the link.</p>
<p class="p1">The <a class=" external" href="https://www.w3.org/TR/wai-aria-practices/#focus_tabindex">tabindex</a> attribute may optionally be used with this role to directly specify the position of the element in the tab order.</p>
<h3>Possible effects on user agents and assistive technology </h3>
<p class="p1">When the link role is added to an element, or such an element becomes visible, the user agent should do the following:</p>
<ul class="ul1"> <li class="li2">Expose the element as having a link role in the operating system's accessibility API.</li> <li class="li2">Fire an accessible link event using the operating system's accessibility API if it supports it.</li>
</ul>
<p class="p1">Assistive technology products should listen for such an event and notify the user accordingly:</p>
<ul class="ul1"> <li class="li2">Screen readers should announce the text of the link or its label when it is focused, along with the fact that it is a link. ARIA links should be included in the screen reader's “List Links” function just like ordinary links, and actions in this dialogue list, such as “Activate Link” or “Move to Link”, should perform the same as they do with ordinary links. </li> <li class="li2">Screen magnifiers may enlarge links.</li>
</ul>
<p> </p>
<p><strong>Note:</strong> Opinons may differ on how assistive technology should handle this technique. The information provided above is one of those opinions and therefore not normative.</p>
<h3>Examples</h3>
<h4>Example 1: <strong>Adding the role in the HTML code</strong></h4>
<p class="p2">The snippet below shows how the link role is added directly into the html source code. </p>
<pre class="brush: html">&lt;div role=”link”&gt;A link&lt;/div&gt;</pre>
<h4 class="p1"><strong>Example 2: Accessible link build from an application using span</strong></h4>
<pre class="brush: html">&lt;script type="text/javascript"&gt;
sap = {ui:{keycodes:{SPACE:32, ENTER:13 }}};
//handles clicks and keydowns on the link
function navigateLink(evt) {
    if (evt.type=="click" ||
        evt.keyCode == sap.ui.keycodes.SPACE ||
        evt.keyCode == sap.ui.keycodes.ENTER) {
        var ref = evt.target != null ? evt.target : evt.srcElement;
        if (ref) window.open(ref.getAttribute("href"),"_blank");
    }
}
&lt;/script&gt;

&lt;body role="application"&gt;

    &lt;h3&gt;Simple Link build with a span&lt;/h3&gt;
    &lt;span href="https://www.w3c.org" onkeydown="navigateLink(event)" onclick="navigateLink(event)" tabindex="0" id="link1" role="link" class="link"&gt;Activate this link using the space bar or enter key&lt;/span&gt;&lt;br /&gt;

&lt;/body&gt;</pre>
<h3>Working Examples:</h3>
<ul> <li class="li1"><a class=" external" href="https://codetalks.org/source/widgets/link/link.html">https://codetalks.org/source/widgets/link/link.html</a></li> <li class="li1"><a class=" external" href="https://codetalks.org/source/widgets/link/link.sample.html">https://codetalks.org/source/widgets/link/link.sample.html</a></li>
</ul>
<h3>Notes </h3>
<p class="p1">If pressing the link triggers an action but does not change browser focus or navigate to a new page, you might wish to consider using the <a class=" external" href="https://www.w3.org/TR/wai-aria/roles#button">button</a> role instead of the link role.</p>

<h3 class="p1">ARIA attributes used</h3>
<ul class="ul1"> <li class="li2"><a class=" external" href="https://www.w3.org/TR/wai-aria/roles#link">link</a></li>
</ul>
<h3 class="p1">Related ARIA techniques </h3>
<ul class="ul1"> <li class="li2"><a class=" external" href="https://www.w3.org/TR/wai-aria/roles#button">button</a> role</li>
</ul>

<h3>Compatibility</h3>
<p class="comment">TBD: Add support information for common UA and AT product combinations</p>
<h3>Additional resources</h3>
<ul> <li> <p class="p1">ARIA Best Practices - Link Role: <a class=" external" href="https://www.w3.org/TR/wai-aria-practices/#link">https://www.w3.org/TR/wai-aria-practices/#link</a></p> </li>
</ul>
Revert to this revision