A visitor tabs into your embedded feed, reads the first line of a caption, and hits a dead end. The rest of the text is there visually — cut off with an ellipsis — but nothing on the page will reveal it without a mouse. That is instagram feed embed caption truncation expand button accessibility in one sentence: the truncated state must be a real, named, keyboard-operable control, and the expanded text must be announced once, cleanly.
This guide is a build-and-test procedure. It assumes you already have a feed rendering inside your page (if not, start with how to embed an Instagram feed on your website), and it focuses on the caption clamp itself rather than general feed setup.
Why a hover-reveal caption fails before you write any code
The common shortcut is a CSS-only reveal: the caption is clamped with -webkit-line-clamp, and the full text appears on hover. It looks fine in a desktop browser and breaks in at least three predictable ways.
- Touch devices have no hover state. A tap may fire a hover emulation once, but a second tap usually navigates to the post instead. The full caption is effectively unreachable.
- Keyboard-only users cannot hover. Tabbing to a card does not open a tooltip, and there is no button to press.
- Screen readers never receive the hidden text. If the expanded copy is hidden with
display: noneand only revealed on hover, assistive tech sees the clamped version or nothing at all.
There is a fourth problem: hover reveals are usually positioned absolutely, so they overlap neighbouring cards and get clipped by the feed container's overflow: hidden.
The fix is not a cleverer hover. It is a real control. Once you accept that, the rest of the work is choosing the right pattern and wiring it correctly.
Inventory the caption states your embed can produce
Before building, list every state the feed can render. This prevents the classic mistake of adding an expand button to posts that do not need one, which clutters the feed and adds pointless tab stops.
| State | What the user sees | What the DOM should contain |
|---|---|---|
| Fully shown | Entire caption, no clamp | Plain text, no button |
| Clamped | Short excerpt plus ellipsis | Clamped text plus an expand button |
| Expandable | Same as clamped, but a control exists | Button with aria-expanded="false" |
| Expanded | Full caption | Full text visible, button label changes, aria-expanded="true" |
| Image-only post | Image, empty or very short caption | No button; the image needs its own alt text |
Compare the character length of the caption against your clamp threshold server-side or at render time, and emit the button only when the text actually overflows. A button that expands one line of text is noise.
The image-only row matters more than it looks. When the caption is the only textual content and it is empty, the image's alt attribute becomes the sole description. The MDN reference on the img element and its alt attribute notes that browsers may replace the image with the alt text when images do not load, and that an empty alt="" marks the image as decorative. Do not use alt="" on a post image that carries meaning — you would strip the only text a screen reader user gets. Pair this with the writing guidance in our Instagram feed alt text and captions accessibility guide.
Choose the reveal pattern: inline expand or modal dialog
The decision is about how much text arrives and how much layout you can afford to move.
Use an inline expand button when:
- The full caption fits comfortably in the card without pushing the grid into a shape nobody designed.
- The caption is a paragraph or two, typical of most posts.
- You want the simplest keyboard experience — no focus trap, no Escape handling, no focus return logic.
Use a modal dialog when:
- Captions are long, multi-paragraph, or contain lists and line breaks that need structure to be understood.
- You already open a lightbox for the image, and a second overlay would be confusing.
- The caption cannot fit in the card without breaking the grid.
If you take the dialog route, the WAI-ARIA Authoring Practices Dialog (Modal) Pattern sets the expectations: mark the container with role="dialog" and aria-modal="true", give it an accessible name via aria-labelledby or aria-label, move focus into the dialog on open, keep Tab and Shift+Tab inside it, close on Escape, and return focus to the invoking element when it closes. It also warns that if content includes multiple paragraphs or lists, focus the first static element with tabindex="-1" so the text can be read in order rather than announced as one unbroken string.
If you build the dialog, do the focus containment properly — our modal lightbox focus trap guide walks through containment and return. For the majority of truncated captions, though, the inline button is the better default: fewer moving parts, less to break, nothing to trap.
Build the expand button correctly
Four attributes carry the whole pattern.
<div class="ig-caption" id="caption-4281">
<p class="ig-caption__text" data-clamped="true">
Behind the scenes at the workshop this week — we finally got the new
cutting table levelled and the first test cuts came out cleaner than…
</p>
<button
type="button"
class="ig-caption__toggle"
aria-expanded="false"
aria-controls="caption-4281-text"
>
Read more
</button>
</div>
Points that matter:
- Use a real
<button>element. Not adivwith a click handler. A native button is focusable, activatable with Enter and Space, and announced as a button without extra ARIA. - Give it a visible label. "Read more" is visible text; do not replace it with an icon-only control. A visible label is also the accessible name, so you do not need
aria-label. - Keep
aria-expandedin sync. Flip it in the same handler that toggles the class. If the state and the visual disagree, screen reader users get a lie. - Make
aria-controlspoint at a stable id. Generate the id from the post id at render time so it survives re-renders. A danglingaria-controlsreference is worse than none.
When expanded, change the visible label to "Show less" so the button's purpose is obvious both visually and in the accessibility tree. Do not swap the button for a plain text node — keep the control in place so keyboard users stay anchored and can collapse again.
Stop the truncated and expanded text from being announced twice
This is the subtle bug. A careless implementation leaves both copies in the accessibility tree: the clamped paragraph plus the full text in a hidden-but-present element. Screen reader users hear the caption twice, or hear a fragment followed by the whole thing.
Rules that prevent it:
- One text node, two visual states. Prefer the same paragraph whose clamp is removed on expand, rather than injecting a second copy. Nothing duplicates because nothing was duplicated.
- If you must keep two copies, remove the shorter one from the tree. Apply
hidden(ordisplay: none) to the clamped copy while the expanded copy is shown, and the reverse when collapsed. Never leave both readable. - Do not rely on
aria-hiddenalone for the copy that should be read.aria-hidden="true"hides from assistive tech but leaves it focusable if it contains links — a focusable element inside anaria-hiddensubtree is a known trap. - Do not force an announcement of the new text. The user pressed the button; keeping focus on the button and revealing the text below it is enough. Live region shouting is for dynamic content the user did not request, not for content they just asked to see.
Test it by listening: with a screen reader running, activate the button and confirm the caption is spoken once, in order, and that the button's state change is announced.
Reserve space so expanding a caption does not shift the grid
An expanding card changes its height. If your grid rows are auto-sized, one card growing pushes everything below it down — a layout shift that also moves the keyboard focus target a user was about to reach.
Mitigations, in order of preference:
- Set a minimum height on the caption block sized for the expanded state (two or three lines), so collapsed cards simply have breathing room. Zero shift, and no code beyond CSS.
- Clamp to a fixed line count with
-webkit-line-clampand a matchingmin-height, then remove the clamp on expand. The block already owns the space it needs. - Let it grow, but only within the card. If the card is in a horizontal row with fixed row height, growth spills rather than pushes. Confirm with an overflow check at 375px width.
Then measure. Open Chrome DevTools, run the Performance panel, expand a caption, and watch the cumulative layout shift entry. Do it at 375px width, where cards are widest relative to the viewport and wrapping is most aggressive. The performance work overlaps with our placeholder layout shift fix and the broader click-to-load facade guide if the feed itself loads late.
For context on why field data beats a single lab run, Google's guide to optimizing Largest Contentful Paint recommends looking at real-user data from the Chrome User Experience Report or your own RUM before acting on lab numbers, since lab tests may not represent actual visitor experience. Apply the same discipline to CLS: trust field data for the verdict, use the lab for the fix.
Pre-launch check: keyboard, screen reader, and layout
Run this list against a staging page with at least one short caption, one long caption, and one image-only post.
- Tab through the feed. The expand button receives focus in a logical order and has a visible focus ring.
- Press Enter on the button. The caption expands; pressing Enter again collapses it.
- Press Space on the button. Same result — native buttons handle both.
- Read the button's accessible name in DevTools' accessibility pane. It should say "Read more" (or your label) and expose
expanded: false. - Expand a caption with a screen reader running. The full text is read once, not twice.
- If a dialog is used: Escape closes it, focus returns to the exact post's button, and Tab never leaves the dialog while open.
- Expand the longest caption at 375px width. The grid does not jump; check CLS in the Performance panel.
- Confirm no button appears on posts whose caption fits fully or is empty.
- Confirm the image-only post has real
alttext rather than an empty attribute. - Zoom to 200%. The button label remains visible and does not overlap the caption.
If any step fails, fix the cause rather than adding a second control to compensate.
Document the pattern so image swaps do not silently drop the button
Feeds get rebuilt. Someone swaps the layout template, a theme update replaces the caption partial, and the button quietly disappears while the clamp CSS stays. The result is a caption that looks truncated with no way to open it — worse than before you started.
Leave a short note in your theme or component README covering:
- The clamp threshold and where it is calculated.
- The exact markup contract:
buttonelement,aria-expanded,aria-controlsid format, visible label strings for both states. - The rule that the two text copies must never both be readable.
- The reserved min-height value and the 375px CLS test that validates it.
Add a smoke test to your release checklist: render one long-caption post and assert the button exists and has aria-expanded="false". That single assertion catches most regressions.
Where WidgetJar fits
WidgetJar is an embeddable widget platform: you configure widgets in the panel, then install the embed script on your registered website domain. The Instagram feed widget renders the feed for you, so your job is the caption layer on top — the clamp, the button, and the tests above. If you have not installed it yet, start at the Instagram feed widget page, then come back to this guide to make sure every truncated caption is reachable by keyboard and announced exactly once.