Halloween Sale 15% off Ends in See the plans
Universal

Accessibility Toolbar With Text Size, Contrast and Link Highlighting

Adds a small floating accessibility button that opens a panel with larger text, high contrast, highlighted links, a readable font and a reset option. Choices are remembered on the visitor's device.

Don’t have WPIDE yet? Install it on your site

Code

<div class="wpide-a11y-bar">
    <button type="button" class="wpide-a11y-open" aria-expanded="false" aria-controls="wpide-a11y-panel">Accessibility options</button>
    <div id="wpide-a11y-panel" class="wpide-a11y-panel" hidden>
        <button type="button" data-a11y="big" aria-pressed="false">Larger text</button>
        <button type="button" data-a11y="contrast" aria-pressed="false">High contrast</button>
        <button type="button" data-a11y="links" aria-pressed="false">Highlight links</button>
        <button type="button" data-a11y="font" aria-pressed="false">Readable font</button>
        <button type="button" data-a11y="reset">Reset</button>
    </div>
</div>
<style>
.wpide-a11y-bar{position:fixed;right:12px;bottom:12px;z-index:99991;font:15px/1.4 system-ui,sans-serif;}
.wpide-a11y-bar button{display:block;width:100%;margin:0 0 6px;padding:10px 14px;border:2px solid #fff;border-radius:6px;background:#1d2327;color:#fff;text-align:left;cursor:pointer;min-height:44px;}
.wpide-a11y-bar button[aria-pressed="true"]{background:#2271b1;}
.wpide-a11y-bar button:focus-visible{outline:3px solid #f0b849;outline-offset:2px;}
.wpide-a11y-panel{margin-bottom:6px;}
html.wpide-a11y-big{font-size:125%!important;}
html.wpide-a11y-contrast body,html.wpide-a11y-contrast body *:not(.wpide-a11y-bar *){background-color:#000!important;color:#fff!important;border-color:#fff!important;}
html.wpide-a11y-contrast a:not(.wpide-a11y-bar *){color:#ff0!important;}
html.wpide-a11y-links a:not(.wpide-a11y-bar *){text-decoration:underline!important;outline:2px dashed currentColor;outline-offset:2px;}
html.wpide-a11y-font body *:not(.wpide-a11y-bar *){font-family:Verdana,Tahoma,sans-serif!important;letter-spacing:.03em;}
</style>
<script>
(function () {
    var root = document.documentElement, key = 'wpideA11y', state = {};
    var open = document.querySelector('.wpide-a11y-open'), panel = document.getElementById('wpide-a11y-panel');
    if (!open || !panel) { return; }
    try { state = JSON.parse(localStorage.getItem(key) || '{}') || {}; } catch (e) { state = {}; }
    function render() {
        ['big', 'contrast', 'links', 'font'].forEach(function (k) {
            root.classList.toggle('wpide-a11y-' + k, !!state[k]);
            var b = panel.querySelector('[data-a11y="' + k + '"]');
            if (b) { b.setAttribute('aria-pressed', state[k] ? 'true' : 'false'); }
        });
        try { localStorage.setItem(key, JSON.stringify(state)); } catch (e) {}
    }
    open.addEventListener('click', function () {
        var expanded = open.getAttribute('aria-expanded') === 'true';
        open.setAttribute('aria-expanded', expanded ? 'false' : 'true');
        panel.hidden = expanded;
    });
    panel.addEventListener('click', function (e) {
        var b = e.target.closest('[data-a11y]');
        if (!b) { return; }
        var k = b.getAttribute('data-a11y');
        if (k === 'reset') { state = {}; } else { state[k] = !state[k]; }
        render();
    });
    document.addEventListener('keydown', function (e) {
        if (e.key === 'Escape' && !panel.hidden) { panel.hidden = true; open.setAttribute('aria-expanded', 'false'); open.focus(); }
    });
    render();
})();
</script>

Notes

A toolbar helps some visitors but does not replace fixing accessibility problems in the theme itself.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.