Show glossary definitions on your site
With the glossary tooltip, any link from your site to a glossary.io term, like ActivityPub, gets a wavy underline, and its short definition appears when a visitor hovers over it or reaches it with the keyboard. Readers get the meaning without leaving your page.
Install it
- Ask for access. glossary.io answers only the sites on its list, so send a request with your site's address. You'll get an email once it's approved.
- Add the script to every page that links to terms, just before
</body>:<link rel="dns-prefetch" href="//glossary.io"> <script async src="https://glossary.io/glossary-tooltip.js"></script> - Link words to their glossary pages. Use the address of the term's page on glossary.io:
Find terms with the search.<a href="https://glossary.io/activitypub/">ActivityPub</a>
How it works
- A link is styled once its definition has loaded, so a link to a page that isn't a term stays a plain link.
- Pages without term links make no requests. Otherwise each term's definition (about 200 bytes) loads as its link nears the screen, once per page view.
- The tooltip opens on hover and on keyboard focus, stays open while the pointer is on it, and closes with Escape. While it's open, screen readers announce the definition with the link.
- On a site that isn't on the list, the links stay plain links and nothing breaks. The script tries twice, then stops, so you'll see two refused requests in the browser console until your site is approved.
Leave a link plain
Add rel="nofollow" to the link, or data-glossary="off" to it or to any element around it:
<a href="https://glossary.io/activitypub/" data-glossary="off">ActivityPub</a>Match your colors
Set any of these on :root in your stylesheet:
| Variable | Default | Colors |
|---|---|---|
--glossary-link-color | #B22D47 | Term links |
--glossary-link-hover-color | #336D46 | Term links on hover |
--glossary-underline-color | #ccc | The wavy underline |
--glossary-tooltip-background | #050520 | The tooltip |
--glossary-tooltip-color | #F4F5F7 | The tooltip's text |
:root {
--glossary-link-color: #0e52ae;
--glossary-tooltip-background: #222;
}Host the script yourself
You can serve your own copy of glossary-tooltip.js from your site; it still loads definitions from glossary.io. Give the file a name that changes with its content (like glossary-tooltip.5644e6d0.js), so browsers pick up a new version right away, and update your copy now and then.