Instagram feed embed modal lightbox aria-labelledby aria-describedby

Label your Instagram feed embed modal lightbox with aria-labelledby and aria-describedby, avoid duplicate announcements, and run a keyboard and screen reader…

James HollowayWeb Development Lead8 min read

An Instagram feed embed modal lightbox aria-labelledby aria-describedby setup is what decides whether a screen reader user hears "Post by studio.kite, 12 March" or just "dialog". When a visitor activates a grid thumbnail, focus moves into an overlay, and the assistive technology announces the dialog's name first. If that name is missing, vague, or points at the wrong node, the post is effectively unlabeled until the user manually explores the container. This guide shows how to name the dialog with a visible caption or a stable string, describe it with just enough post context, and verify the result before launch.

The pattern here is a post detail overlay inside an embedded feed, not a marketing popup. If you need the wider containment story, the focus trap guide for Instagram feed lightbox dialogs covers Tab looping and return focus. This article stays on the two labelling attributes and the announcement they produce.

What a screen reader announces when a lightbox opens

A lightbox is a dialog: a window overlaid on the page, with everything behind it inert while it is open. The ARIA authoring practices state that the dialog container should be a role="dialog" element with aria-modal="true" and either a value on aria-labelledby pointing at a visible dialog title, or a label from aria-label, per the WAI-ARIA dialog pattern. The name is announced as the user enters the dialog, before they start reading post content.

So the label is not decoration. It is the first sentence a screen reader user hears about the post they just opened. A name like "dialog" tells them nothing; a name like "Post by studio.kite: spring collection shelf" tells them they landed in the right place.

Two details from the same source matter for the description attribute. The APG notes that aria-describedby is generally helpful only when the descriptive content is simple, and it advises omitting it when the dialog holds semantic structures that would be hard to follow as one unbroken string. On close, focus should return to the element that invoked the dialog.

Two labelling options: visible caption versus stable string

There are two defensible approaches, and the choice depends on what your feed renders.

  • aria-labelledby pointing to a visible caption. Best when the lightbox shows the post caption or a heading as real text. The name then matches what sighted users see, and the same text serves both audiences. This is the more robust option because the label cannot drift away from the visible content.
  • aria-label with a stable string. A reasonable fallback when the visible design has no suitable heading node, for example a media-only overlay. Build the string from fields you already hold, such as author display name plus a photo index. Keep it stable across opens so users do not hear a different name for the same post on a second visit.

Avoid combining both in ways that produce a double name, and never leave the dialog unnamed. Also resist pointing aria-labelledby at text that is visually hidden only to make the audit pass: if the reference target is not part of the rendered content, you have effectively created a hidden label with extra steps.

If your product layer renders the grid and overlay for you, check what it emits before overriding. WidgetJar's Instagram feed widget is configured in the panel and installed with the embed script on your registered domain, and the no-code Instagram feed embed walkthrough shows the install path; labelling is something you verify and, where the DOM allows, adjust in your own CSS and wrapping markup rather than guessing at internal features.

Building aria-labelledby correctly

When you reference a text node, three rules keep announcements clean.

  1. Unique ID per post. The caption node inside the overlay needs an ID that includes a post-specific token, not a fixed string like caption. Two posts open in sequence must never share an ID, or your reference resolves to whichever node the document resolves first.
  2. No duplicate IDs across grid and lightbox. If the grid card also carries a caption node with the same ID, you now have two elements claiming it. Either keep grid captions unlabelled by the dialog, or generate distinct IDs such as grid-caption-<id> and lb-title-<id>.
  3. Order of references. aria-labelledby accepts multiple IDs separated by spaces, concatenated in order. Put the post title or author first and the secondary phrase second, so the name reads as a sentence rather than a jumble.

A minimal, honest structure looks like this (IDs are illustrative; your embed markup will differ):

<div role="dialog" aria-modal="true"
     aria-labelledby="lb-title-4821"
     aria-describedby="lb-meta-4821">
  <h2 id="lb-title-4821">Post by studio.kite: spring collection shelf</h2>
  <p id="lb-meta-4821">Posted 12 March</p>
  <img src="post-4821.jpg" alt="Shelf of folded linen in three pastel shades">
  <button type="button">Close</button>
</div>

The img element's alt matters here because the lightbox usually shows the photo at full size; the MDN reference for img notes that browsers may replace an image with its alt text when it cannot be displayed, which makes alt part of the same announcement chain as the label. The Instagram feed alt text and captions guide covers writing that text from post captions.

If you use the native <dialog> element instead of a custom container, remember the platform gives you modal behaviour: showModal() renders the rest of the page inert, and the element is exposed with an implicit modal state, as the MDN dialog element reference describes. The same MDN page warns not to put tabindex on the dialog element itself, because it is not interactive and does not receive focus; its contents do.

Using aria-describedby without over-announcing

Description is where most lightboxes go wrong. The dialog name is announced once, then the initial focus element is announced, and the description is typically read along with them. If that description is the entire caption, the user hears the post twice: once as a description and again when they navigate to the caption text.

Keep the description short and additive:

  • Post date, author handle, or media count.
  • A brief context line such as "Carousel, 4 images" if your overlay renders one.
  • Nothing that repeats the label verbatim.

Omit aria-describedby altogether when the overlay contains rich structure: a carousel with controls, a table, or several paragraphs. The APG explicitly recommends leaving it off in that case, because a long description read as one flat string is harder to use than navigating the structure directly.

Common failure cases to look for

  • Unlabeled dialog. No aria-labelledby and no aria-label. The screen reader may announce only the role.
  • Label pointing at hidden text. The reference target exists in the DOM but is not rendered, so some assistive technologies resolve nothing useful.
  • Duplicate IDs across grid and overlay. The dialog borrows the grid card's caption ID and announces the wrong text or an empty string.
  • Leftover aria-hidden on the opener. On close, focus returns to a card or button that still carries aria-hidden="true", so the user is parked on something their screen reader skips. The APG notes that where aria-hidden is used to make background content inert, the dialog must not be a descendant of any element carrying it.
  • Focus landing outside the dialog. The overlay opens but focus stays on the grid, so the first announcement is the trigger, not the post.
  • Description equals the caption. The user hears the whole caption twice.

Keyboard and screen reader test script

Run this on the page where the feed is installed, with a desktop screen reader and one keyboard-only pass:

  1. Tab to a grid thumbnail and confirm it has an accessible name.
  2. Press Enter. Confirm focus moves inside the dialog and the announced name identifies the post, not just "dialog".
  3. Repeat on a second post. Confirm the name differs and no duplicate-ID warning appears in the browser dev tools.
  4. Listen for the description. If it repeats the caption you just heard, trim it.
  5. Tab through the overlay; check focus stays inside and reaches the close button.
  6. Press Escape. Confirm the dialog closes.
  7. Confirm focus returns to the exact thumbnail you opened, and that its name is announced again.

For a broader pass across all modal patterns on your site, reuse the steps in the modal dialog accessibility test script.

Pre-launch checklist: keep labels, alt text and captions aligned

  • Every dialog instance has a name from either aria-labelledby or aria-label, never both in conflicting form.
  • Referenced IDs are unique per post and unique between grid and overlay.
  • The label reads as a sentence when references are concatenated in order.
  • aria-describedby adds context only; it does not duplicate the caption.
  • Alt text on the full-size image describes content rather than repeating the caption verbatim.
  • Close returns focus to the trigger, and the trigger is not hidden from assistive technology.
  • You have run the seven-step script above on at least two posts.

Treat the label as part of your content workflow, not a one-off patch: when an editor changes the caption style, the label should still resolve to something meaningful.

Next step

If you are setting up the feed itself, configure your posts in WidgetJar, install the embed script on your registered domain, then run the test script above on the live page. Start with the Instagram feed widget setup and keep this labelling checklist beside it so the dialog is named correctly the first time.

  • instagram feed embed modal lightbox aria-labelledby aria-describedby
  • instagram feed
  • accessibility
  • modal dialog
  • screen readers
  • keyboard testing

Written by

James Holloway

Web Development Lead at WidgetJar

Keep reading

Get started

Your next lead is one line away.

Pick a design, make it yours and paste a single script tag. Every widget type is included, and you do not need a credit card to start.

<script src="https://cdn.widgetjar.com/wj-assets/embed.js" defer></script>