Whakerexa > Components > Links

Links

Native link

The native <a> element is fully styled by wexa.css. No JavaScript required. Color, hover and visited states are applied automatically. Add .external-link to append an external link icon after the text.

<a href="page.html">Internal link</a>
<a href="https://example.org" class="external-link">External link</a>

Variables

Variable Role Default (light)
--a-color Link text color; the external-link mark takes the color of the text it follows rgb(8, 92, 148)

An element that carries role="link"

A role announces a link to the reader who listens, and wexa.css draws one for the reader who looks, on whatever element carries it. The icon of .external-link comes with it, and so does the fit of the box around an image it holds. Being reached from the keyboard is the author's part: the role says what it is, tabindex says it can be reached.

A span that is a link A span that leaves the page The logo of Whakerexa
<span role="link" tabindex="0">A span that is a link</span>
<span role="link" tabindex="0" class="external-link">A span that leaves the page</span>
<span role="link" tabindex="0"><img src="logo.webp" alt="The logo of Whakerexa" width="64"></span>

The marks of a link

A link that does what a reader expects carries no mark. Four do not, and each says so after its text: one leaves the document, one stays inside the page, one hands over a file, one opens a mail program. A fifth says nothing of the address: it is the invitation of the one who writes — read on.

Two of them are asked for, because the address does not say them: .external-link, since an absolute address can be of this very site, and .anchor-link, since an anchor is also how a table of contents is written — marking every one of them would mark the rule instead of the exception. The other two are read from the address and need nothing: download and mailto:. The fifth, .more-link, is asked for too, and anywhere: it draws the arrow a page would otherwise type at the end of its text, where a screen reader would read it aloud.

The three classes name no element. What leaves the document leaves it whether a reader follows an <a>, something that carries role="link", or a button that navigates: the class is written where the fact is true, and the mark is drawn there. The two that are read from an address stay on an anchor, since a button has none.

<a href="#main-content" class="anchor-link">Back to the content</a>
<a href="icon.svg" download>The icon file</a>
<a href="mailto:contact@sppas.org">Write to us</a>
<a href="https://sppas.org" class="external-link">SPPAS</a>
<a href="bibliography.html" class="more-link">Read on</a>
<button class="external-link">A button that leaves</button>

A mark is drawn by the framework, not written in the text: a screen reader does not read it, and the color it takes is the color of the text it follows. A page that wants none of the two automatic ones says so in its own stylesheet:

a[download]::after,
a[href^="mailto:"]::after {
    content: none;
}

LinkController — when and why

A plain <a href> is not enough when:

LinkController attaches both click and keyboard listeners to any element identified by ID, reads href or data-href as the target URL, and opens it according to data-target. Requires JavaScript.

handleLinks

handleLinks(ids) registers click and Enter listeners on the listed element IDs.

URL resolution. href is used if present and non-empty. On elements that cannot carry href (e.g. <button>), use the data-href attribute instead — LinkController will read it as a fallback.

Target. Set data-target on the element: _blank (default — opens in new tab), _self (same page), or the ID of an <iframe> on the page.

Call LinkController.initFocusable() once at page load to make elements that carry data-href (but no href and no explicit tabindex) reachable via Tab.

Open in new tab

<a id="link-blank" role="button" data-href="https://sppas.org">
    Open SPPAS (new tab)
</a>
<!-- data-target defaults to _blank -->

lc.handleLinks(['link-blank']);

Open in same page

<a id="link-self" role="button" data-href="../index.html" data-target="_self">
    Open index (_self)
</a>

lc.handleLinks(['link-self']);

Open in iframe

<button id="link-iframe"
        data-href="https://example.org"
        data-target="preview-iframe">Load in iframe</button>
<iframe id="preview-iframe" title="Preview area"></iframe>

lc.handleLinks(['link-iframe']);

handleLinksWithParameters

handleLinksWithParameters(ids) behaves identically to handleLinks, but appends the current accessibility state (color scheme, contrast mode) as URL parameters via Wexa.accessibility.setUrlWithParameters(). Use this when the destination page is also a Whakerexa application and should open in the same accessibility state as the current page.

<a id="link-params" role="button" data-href="../index.html" data-target="_blank">
    Open index with accessibility params
</a>

lc.handleLinksWithParameters(['link-params']);