Make Elfsight Widgets WCAG Compliant

Our organization runs staff profile pages that embed Elfsight’s LinkedIn Feed widget, and an accessibility audit (WCAG 2.1/2.2 AA) turned up several real, out-of-the-box issues in the widget’s default markup and styling:

  • The widget strips keyboard focus outlines from every interactive element (outline: none !important), leaving keyboard users with zero visual indication of what’s focused.
  • Engagement counters (Like, Comment) carry an aria-label that doesn’t include the number shown next to them, so a voice-control user who reads the number aloud can’t activate the control (WCAG 2.5.3 Label in Name).
  • Secondary text (e.g. the link-preview domain) renders at roughly 3.5:1 contrast against its background, under the 4.5:1 AA minimum.
  • Carousel pagination dots have a touch target under 24×24px (WCAG 2.5.8), and are plain <div>s with no role, so adding an aria-label to them without a role produces an invalid ARIA state.

We were able to resolve all of this using Elfsight’s own Custom CSS and Custom JS panels — no need to touch the widget’s underlying code — with a script generic enough to paste, unchanged, into every instance of the widget across our site. It’s a solid workaround, but it would be far more reliable coming from Elfsight directly: hashed class names shift between widget rebuilds, which broke our fixes more than once and required re-diagnosing against the live DOM each time. Native support for visible focus states, accurate ARIA naming, and AA-compliant default contrast in the widget settings would remove the need for a Custom CSS/JS workaround entirely.

**CSS Example:**

/*
 * WCAG remediation CSS for Elfsight "LinkedIn Feed" widgets
 * Paste this exact file into the Custom CSS panel of EVERY LinkedIn Feed
 * widget instance (e.g. one per staff profile page), then click Publish.
 *
 * IMPORTANT: write PLAIN selectors here, with no widget-ID or wrapper
 * class of any kind. Elfsight's Custom CSS panel automatically prepends
 * its own scoping class (".eapps-linkedin-feed-<id>-custom-css-root") to
 * every selector you write, on publish. An earlier version of this file
 * included that same scope as a manual wildcard selector, which made
 * Elfsight stack its own literal scope in front of it as a *descendant*
 * combinator -- requiring the widget to contain a second copy of itself
 * nested inside, which can never match. That's why nothing in the
 * previous version ever took effect despite being published. Confirmed
 * by inspecting exactly what Elfsight injected onto the live page.
 * Because Elfsight scopes automatically per widget instance, plain CSS
 * here is *already* generic across every profile page -- no manual
 * scoping needed at all.
 */

/* ---------------------------------------------------------------------
 * 1. CRITICAL — WCAG 2.4.7 Focus Visible (Level AA)
 * The widget's own base CSS does:
 *   .eubOdX, .eubOdX * { outline: none !important; }
 * which removes the focus ring from every interactive element in the
 * widget -- Like/Comment links, share button, "see more" toggle,
 * carousel arrows, pagination dots, avatar/name links. Restore a
 * visible ring, overriding the !important.
 * ------------------------------------------------------------------- */
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid rgb(10, 102, 194) !important; /* LinkedIn blue, distinct from post text/links */
  outline-offset: 2px !important;
}

/* Fallback for browsers without :focus-visible support */
a:focus,
button:focus,
[tabindex]:focus {
  outline: 2px solid rgb(10, 102, 194) !important;
  outline-offset: 2px !important;
}

/* ---------------------------------------------------------------------
 * 2. WCAG 1.4.3 Contrast (Minimum), Level AA
 * Link-preview domain text (e.g. "www.livehire.com"). Confirmed live at
 * rgba(17,17,17,0.5); ACE measured the rendered result as #828282 on
 * #f3f3f3 -> 3.46:1, failing the 4.5:1 minimum. Raising to 0.7 opacity
 * gives ~6.7:1 against that same #f3f3f3 background.
 * ------------------------------------------------------------------- */
.hDRIkU {
  color: rgba(17, 17, 17, 0.7); /* matches the 0.7 opacity used elsewhere (timestamp, share button) */
}

/* Optional consistency pass: the link icon inside that same domain row
 * sits at the same 0.5 opacity. Confirmed live it clears the 3:1
 * non-text minimum (≈3.5:1) but with little margin — bump to match.
 * Scoped via ".hDRIkU svg" rather than the icon's own hashed container
 * class, which has already proved unstable across rebuilds. */
.hDRIkU svg {
  fill: rgba(17, 17, 17, 0.7);
  color: rgba(17, 17, 17, 0.7);
}

/* ---------------------------------------------------------------------
 * 3. WCAG 2.5.8 Target Size Minimum (Level AA, WCAG 2.2)
 * Carousel pagination dots: confirmed live their ::after hit-area pad is
 * inset: -2px (≈10x10px total against a 6px dot) -- under the 24x24
 * CSS px minimum. Targets the stable "es-bullets-control-item" class,
 * not the dot's own hashed class (already confirmed to have drifted
 * once). A ::after pseudo-element belongs to the element itself, not to
 * whichever class name declared it, so this overrides "inset" no matter
 * what hash the vendor's own rule currently uses.
 * ------------------------------------------------------------------- */
.es-bullets-control-item::after {
  inset: -9px !important; /* 6px dot + 9px each side = 24px total hit area */
}

/* NOTE: the carousel prev/next arrow buttons were checked live and are
 * already 32x32px (set inline by the widget), clearing the 24x24
 * minimum -- no CSS needed for them right now. */

/* ---------------------------------------------------------------------
 * 4. Styling request: bold the "Read more" / "Read less" post-truncation
 * toggle (not a WCAG failure -- its 6.2:1 contrast already passes AA --
 * just a visual weight change). Confirmed live text is "Read more" at
 * font-weight 400. Its own class is hashed and has already drifted once
 * (was .jicbUD, now something else) -- scoped via the stable
 * "es-text-shortener-control" class instead.
 * ------------------------------------------------------------------- */
.es-text-shortener-control {
  font-weight: 700;
}
**JS Example:**

/*
 * WCAG remediation JS for Elfsight "LinkedIn Feed" widgets — GENERIC VERSION
 * Paste the exact same file into the Custom JS Editor of EVERY LinkedIn
 * Feed widget instance (e.g. one per staff profile page) — nothing to edit
 * per page. It auto-discovers any widget on the page by ID prefix rather
 * than one specific widget's ID, and keeps watching for widgets that
 * mount later (Elfsight lazy-loads the widget's contents, which can
 * appear well after DOMContentLoaded if it's scrolled into view later).
 * (Elfsight's linter requires let/const, no var — already handled below.)
 *
 * Every fix here is defensive: it only changes an attribute if it's
 * missing or actually wrong, so re-running on every DOM mutation (the
 * widget re-renders on carousel navigation and lazy-loaded content) is
 * idempotent and won't fight with anything the widget already does right.
 */
(function () {
  const WIDGET_SELECTOR = '[id^="eapps-linkedin-feed-"]';
  const ATTACHED_FLAG = 'a11yFixesAttached';

  // 1. WCAG 2.5.3 Label in Name (Level A)
  // Engagement counters (Like, Comment, etc.) carry an aria-label like
  // "Like" that doesn't include the visible count next to it, so a voice
  // control user who speaks the visible number can't activate the control.
  // The label is also rewritten into a natural phrase describing what
  // clicking actually does (opens the post on LinkedIn), rather than a
  // stilted "Like, 3" that just concatenates the two pieces of text.
  function fixCounterLabels(root) {
    const counters = root.querySelectorAll('.es-card-actions-block-layout-block a[aria-label]');
    counters.forEach(function (link) {
      // Cache the widget's original label once. Re-deriving the noun from
      // an aria-label we've already rewritten (the widget re-renders
      // often) would strip/mangle it on every subsequent pass.
      if (!link.dataset.a11yBaseLabel) {
        link.dataset.a11yBaseLabel = link.getAttribute('aria-label').trim();
      }
      const baseLabel = link.dataset.a11yBaseLabel; // e.g. "Like", "Comment", "Repost"
      const visibleText = link.textContent.trim();
      if (!visibleText) return;

      const count = parseInt(visibleText.replace(/[^\d]/g, ''), 10);
      let newLabel;
      if (!isNaN(count)) {
        const noun = baseLabel.toLowerCase();
        const plural = count === 1 ? noun : noun + 's';
        newLabel = count + ' ' + plural + ', view post on LinkedIn';
      } else {
        // No numeric count visible (e.g. "0" shown as blank) - fall back
        // to a plain, still-readable combination rather than guessing.
        newLabel = baseLabel + ', ' + visibleText;
      }

      if (link.getAttribute('aria-label') !== newLabel) {
        link.setAttribute('aria-label', newLabel);
      }
    });
  }

  // Gives a plain, non-interactive element (typically a <div>) the role,
  // focusability and keyboard handling of a real button. A bare <div>
  // has no ARIA role at all, so an aria-label on it with nothing else is
  // flagged as "ARIA attribute conflicts with assigned role" (ACE) --
  // aria-label only means something once the element has an interactive
  // role. This also fixes the keyboard-operability gap that comes with
  // it: a <div>, unlike a real <button>, isn't focusable and doesn't
  // turn Enter/Space presses into clicks on its own.
  function makeFocusableButton(el) {
    if (!el.hasAttribute('role')) el.setAttribute('role', 'button');
    if (!el.hasAttribute('tabindex')) el.setAttribute('tabindex', '0');
    if (!el.dataset.a11yKeyHandler) {
      el.dataset.a11yKeyHandler = 'true';
      el.addEventListener('keydown', function (e) {
        if (e.key === 'Enter' || e.key === ' ' || e.key === 'Spacebar') {
          e.preventDefault();
          el.click();
        }
      });
    }
  }

  // 2. WCAG 4.1.2 Name, Role, Value (Level A)
  // Carousel prev/next arrows are icon-only controls. Elfsight already
  // makes the *container* a fully-formed control on some builds (role
  //="button" + aria-label="Next"/"Previous" set natively) -- if so,
  // leave it and everything inside it alone. Reaching into a descendant
  // and labelling that too creates a second interactive control nested
  // inside the first, which is its own WCAG 4.1.2 failure ("interactive
  // controls nested inside other interactive elements"). Only step in
  // when the container itself has neither a role nor a label.
  function fixCarouselControls(root) {
    const prevContainer = root.querySelector('.es-carousel-arrow-control-container-previous');
    const nextContainer = root.querySelector('.es-carousel-arrow-control-container-next');
    [ [prevContainer, 'Previous post'], [nextContainer, 'Next post'] ].forEach(function (pair) {
      const container = pair[0];
      const label = pair[1];
      if (!container) return;

      if (container.hasAttribute('role') && container.hasAttribute('aria-label')) {
        // Already fully formed. Undo anything an earlier (buggy) run of
        // this script may have added to a nested descendant -- that's
        // exactly what created the "nested interactive controls"
        // failure. Only strips attributes this script itself added
        // (marked by the data-a11y-key-handler flag), never anything
        // the widget vendor put there.
        container.querySelectorAll('[role="button"]').forEach(function (nested) {
          if (nested === container || !nested.dataset.a11yKeyHandler) return;
          nested.removeAttribute('role');
          nested.removeAttribute('tabindex');
          nested.removeAttribute('aria-label');
          delete nested.dataset.a11yKeyHandler;
        });
        return;
      }

      // Nothing set at the container level: label/interact-ify a real
      // <button> inside it if there is one, otherwise the container itself.
      const control = container.querySelector('button') || container;
      if (!control.hasAttribute('aria-label')) control.setAttribute('aria-label', label);
      if (control.tagName !== 'BUTTON' && control.tagName !== 'A') makeFocusableButton(control);
    });

    const bullets = root.querySelectorAll('.es-bullets-control-item');
    bullets.forEach(function (bullet, i) {
      if (!bullet.hasAttribute('aria-label')) {
        bullet.setAttribute('aria-label', 'Go to post ' + (i + 1));
      }
      if (bullet.tagName !== 'BUTTON' && bullet.tagName !== 'A') makeFocusableButton(bullet);

      // Bonus: tell assistive tech which post is currently showing,
      // matching the WAI-ARIA carousel pattern. Kept in sync since this
      // whole function re-runs on every carousel navigation.
      if (bullet.classList.contains('es-bullets-control-item-active')) {
        bullet.setAttribute('aria-current', 'true');
      } else if (bullet.hasAttribute('aria-current')) {
        bullet.removeAttribute('aria-current');
      }
    });
  }

  // 3. WCAG 1.1.1 Non-text Content (Level A)
  // Author avatar images should never announce as an unlabeled graphic.
  // Fall back to the adjacent author name if alt text is missing/empty.
  // (Deliberately avoids the :has() selector -- not universally supported,
  // and a thrown SyntaxError there would break every fix below it.)
  function fixAvatarAlt(root) {
    const avatarContainers = root.querySelectorAll('.es-avatar-container');
    avatarContainers.forEach(function (container) {
      const img = container.querySelector('img');
      if (!img || (img.getAttribute('alt') || '').trim()) return; // already has real alt text

      const card = container.closest('[class*="CardUserBlock"]') || container.closest('.es-carousel-item') || root;
      const nameLink = card.querySelector('a[href*="linkedin.com/in/"], a[href*="linkedin.com/company/"]');
      const name = nameLink ? nameLink.textContent.trim() : '';
      img.setAttribute('alt', name ? (name + ' profile photo') : 'Profile photo');
    });
  }

  // 4. WCAG 1.1.1 / 4.1.2 — verified badge icon
  // The checkmark icon next to a name conveys "verified" visually only.
  // Label it fully enough to stand on its own -- a screen reader user
  // browsing by images/landmarks may land on it without the adjacent
  // name for context, so a bare "Verified" is ambiguous (verified what?).
  function fixVerifiedBadge(root) {
    const badges = root.querySelectorAll('.es-header-name-badge-container');
    badges.forEach(function (badge) {
      if (badge.hasAttribute('aria-label') || badge.getAttribute('aria-hidden') === 'true') return;
      badge.setAttribute('role', 'img');
      badge.setAttribute('aria-label', 'Verified LinkedIn profile');
    });
  }

  // Each fix runs in isolation: a selector issue or unexpected DOM shape
  // in one shouldn't stop the others from applying.
  function runFixes(root) {
    [fixCounterLabels, fixCarouselControls, fixAvatarAlt, fixVerifiedBadge].forEach(function (fix) {
      try {
        fix(root);
      } catch (err) {
        console.warn('[LinkedIn widget a11y fix] ' + fix.name + ' failed:', err);
      }
    });
  }

  // Wire up one widget instance: run the fixes now, then keep re-running
  // them as that instance's own content re-renders (carousel nav etc.).
  // Guarded by a data-attribute so the same widget never gets a second
  // observer if this scan runs again.
  function attachToWidget(root) {
    if (root.dataset[ATTACHED_FLAG]) return;
    root.dataset[ATTACHED_FLAG] = 'true';

    runFixes(root);

    new MutationObserver(function () { runFixes(root); })
      .observe(root, { childList: true, subtree: true });
  }

  function scanForWidgets() {
    document.querySelectorAll(WIDGET_SELECTOR).forEach(attachToWidget);
  }

  function init() {
    scanForWidgets();

    // Elfsight widgets can lazy-mount well after page load (e.g. only
    // once scrolled into view), and a page can carry more than one --
    // keep watching the page for new instances appearing.
    new MutationObserver(scanForWidgets)
      .observe(document.body, { childList: true, subtree: true });
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
  } else {
    init();
  }
})();

Hi there, @user19339 :waving_hand:

First of all, a huge thank you for taking the time to share such detailed feedback and for suggesting possible solutions. We really appreciate the effort you put into testing the widgets and documenting your ideas!

One quick note regarding the CSS adjustments: the reason custom CSS may stop working after widget updates is that temporary classes are being used. For more reliable customizations, we recommend using stable classes, as they are designed to remain consistent across updates. You can find more details about stable classes and CSS customization here: Guide to CSS Codes

Regarding your accessibility suggestions — I’ve discussed them with our developers, and they’ve created tasks to implement the 1st, 2nd, and 4th ideas. We’ll keep you updated as soon as there are any changes available :slightly_smiling_face:

The 3rd suggestion requires a more complex product-level update, so it will take more time to explore. For now, the recommended workaround is to use custom CSS to address this case. We’ll also keep it in mind as a potential global improvement in the future.

Thanks again for helping us make the widgets more accessible! Your feedback is really valuable :raising_hands:

Hi there, @user19339 :waving_hand:

Thank you for waiting!

We’re happy to share that the 1st, 2nd and 4th suggestions have been implemented to the widget. Check it out and let me know if it’s fine now :slightly_smiling_face: