HANIVVRA SUPPORT
Styling email addresses
This page applies to any page, header or footer whose content contains a mailto: link.
An address written as an ordinary mailto: link in the editor is never published as one. At publish time each link becomes a button carrying the address encrypted, and script turns it back into a link when the reader presses it. Nothing on the page contains the address in a form a harvester can read without rendering the page and pressing the button.
That has one consequence for a stylesheet: what the reader first sees is a button, not an a, and it has to be made to look like it belongs.
1. Shape of the markup
Two kinds are published, depending on what the author put inside the link.
The author wrote the address itself — <a href="mailto:sales@example.com">sales@example.com</a>:
<button type="button" class="cms-email-address cms-email-address-reveal" title="Press to show this e-mail address"
data-cms-email-address="…">Show e-mail address</button><noscript> (JavaScript is required to show this e-mail address)</noscript>
There is nothing of the author's to keep, so the label is generic. Pressing it replaces the button with the address as a link, to be read and copied. This one is an action, and may look like a button.
The same shape is used when the link body was empty, and when it held the address inside a longer sentence — anything that would have published the address as text becomes the reveal form.
The author wrote their own words — <a href="mailto:sales@example.com">Contact sales</a>:
<button type="button" class="cms-email-address" title="Press to send an e-mail"
data-cms-email-address="…">Contact sales</button><noscript> (JavaScript is required to use this e-mail address)</noscript>
The author's words are kept, markup and all. Pressing it opens the mail client directly, so this button stands in for a link and should look like one.
2. Classes
| Class | On | Meaning |
|---|---|---|
cms-email-address |
button |
Every published address, both kinds. |
cms-email-address-reveal |
button |
Only the kind that shows the address in place. Absent on the kind that acts as a link. |
cms-email-address-failed |
span |
Replaces a reveal button when the address cannot be decoded. Never appears for the other kind. |
The two kinds are told apart by the presence of the second class, so a rule for the link-shaped one has to exclude it:
.cms-email-address:not(.cms-email-address-reveal) { … } /* looks like a link */
.cms-email-address-reveal { … } /* looks like a button */
3. Making the link-shaped button look like a link
A button brings a border, a background, its own font and centered text, none of which belong mid-sentence. Reset all of it and inherit from the prose around it:
.cms-email-address:not(.cms-email-address-reveal)
{
padding: 0;
border: none;
background: none;
font: inherit;
color: inherit;
text-align: inherit;
cursor: pointer;
}
Then give it whatever your a elements get — color, underline, hover. Matching your own link rules matters more than any particular choice, because this button sits where a link would have been and a reader should not be able to tell.
font: inherit is the one that is easy to forget: without it the button renders in the browser's default interface font and the sentence breaks around it.
4. After it is pressed
On success both kinds replace the button with a plain anchor:
<a href="mailto:sales@example.com">sales@example.com</a>
For the reveal kind the text is the address, with anything the author asked to be prefilled left off. For the link-shaped kind the text is the author's own words, and the mail client opens at the same moment, so the anchor left behind is rarely looked at.
It carries no class. Ordinary a styling applies and nothing more, so it looks like every other link on the page — usually what is wanted. To style it apart, go by context rather than by class:
p a[href^="mailto:"] { … }
5. The failure state
If the page is served from a host other than the one it was published for — a mirror, a copy, a domain that has since changed — the address cannot be decoded. The two kinds behave differently, and only one of them is styleable.
The reveal kind replaces its button with a sentence:
<span class="cms-email-address-failed">This e-mail address can only be shown on the original site.</span>
Keep it readable rather than alarming:
.cms-email-address-failed { color: …; font-style: italic; }
The link-shaped kind raises an alert and leaves its button exactly as it was — nothing is replaced, nothing is added, and the button stays pressable. There is no class, no attribute and no state for a stylesheet to target, so this case cannot be styled at all.
6. Attributes worth styling against
| Attribute | On | Use |
|---|---|---|
data-cms-email-address |
button |
The encrypted address. On every one, so [data-cms-email-address] works as a selector in place of the class. |
title |
button |
Differs between the two kinds — "Press to show this e-mail address" and "Press to send an e-mail". Do not depend on the wording. |
One rule worth having, since both kinds are keyboard controls:
.cms-email-address:focus-visible { outline: 2px solid …; }
A button is focusable and announced as a control, which is why it is used rather than an a without an href, which is neither.
7. Do not restyle
Never set display: none or visibility: hidden on .cms-email-address. The address is not on the page in any other form, so hiding the button removes the only way to reach it.
Leave noscript alone. It is all a reader without JavaScript gets, since there is no address in the markup to fall back to. If the parenthetical reads awkwardly in your design, the fix is different wording, not display: none.
8. Without CSS, and without JavaScript
Unstyled, both kinds render as ordinary browser buttons and both work. The link-shaped one reads oddly mid-sentence, but nothing is broken and nothing is hidden.
Without JavaScript neither button does anything, and the noscript text says so. That is the real cost of the approach: an address published this way is not available to a reader without JavaScript at all. Where that matters, publish a form instead — a form works without JavaScript, and no address appears on the page for a harvester to take.
