How I Write Alt Text for Code Snippets on Social Media The article explains best practices for writing alt text for code snippet screenshots on social media, emphasizing that the goal is to provide a text alternative that conveys the same information as the image. It advises that for short snippets (five lines or fewer), reproducing the exact code is ideal, but for longer code, alt text should be kept succinct—around 120 characters—to avoid overwhelming screenreader users, who may struggle to navigate lengthy descriptions. The author notes that their guidance is based on aggregating advice from blind and low-vision individuals rather than personal experience. Oh, hey It’s a “how to write alt text” post. This is something of a rite of passage for accessibility bloggers. That said, I don’t rely on alt text in my day-to-day browsing. As such, this post is drawn less from my own lived experience and more from aggregating advice given by blind and low-vision people sharing their own lived experiences and preferences. To learn more, I’d especially recommend Veronica Lewis’s guides to writing useful alt text for further guidance. Posting screenshots of code snippets has become something of a staple for programming educators and advocates on social media. Generally, these snippets are meant to serve as an eye-catching way to illustrate some technique being shared in the post. They can be literal screenshots from an editor or, quite commonly, they’re generated with tools such as Carbon. However, oftentimes, these snippets are shared but their alt text leaves a lot to be desired. Sometimes, it’s missing altogether. Other times, it’s vague and unusable, like “Code snippet.” Either way, blind and low-vision programmers aren’t given the opportunity to meaningfully learn from the snippet. What’s the best alt text to provide? Should the alt text just be a copy of the full code? As we’ll see, my answer is the classic accessibility mantra: It Depends™. How Alt Text Is Experienced The goal of alt text is in its name: to provide a viable alternative, in text form, in place of an image. Someone who reads an image’s alt text should generally have the same takeaways as someone who saw the image directly. This is especially critical when the goal of an image is to educate. This means that for screenshots of text, reproducing the text verbatim is often the best alt text. However, the more text there is to reproduce, the more tedious that wall o’ alt text becomes. Not all screenreaders afford their users the ability to pause an image’s alt text readout or to backtrack a few words. Those that do may also add extra clutter the longer the alt text gets. This makes images with very long alt text a commitment, and screenreader users can end up getting lost in the sauce halfway through, faced with the choice to either keep going, start the alt text all over again, or just nope out and skip the rest. This is why, even though screenreaders have no real character limit for alt text these days, it’s still important to keep your alt text succinct. Accessibility advocates sometimes suggest a max length of around 120 characters or so as a general rule of thumb, but context will impact how many characters you actually need. This means your approach to writing alt text for those screenshots of code snippets will probably need to change depending on the length and focus of the snippet. update In a previous version of this post, I said that screenreaders in general don’t allow users to pause or traverse alt text. It’s since been brought to my attention that I was mistaken — JAWS and NVDA definitely do allow traversing alt text in all the same ways as regular text, but VoiceOver does not seem to. Thanks to Ramón on Twitter as well as Ryan and Roberto at work for pointing this out Short, Focused Snippets If your snippet is only a few short lines long I’d say maybe five lines or fewer, but as always, It Depends™ , and focused on a very particular syntax or technique, then I would reproduce the code exactly for the alt text; no more, no less. For example, say our post demonstrates how one could use place-items: center to center an element’s children: The snippet: The alt text: .centered-children { display: grid; place-items: center; } Beautiful. Nice and tidy. As a sidenote, centering in CSS is awesome these days. Medium-Length Snippets Medium-length snippets often establish the relevant syntax or technique in some wider context. This context can be useful to see how the technique would be used in the wild, but it also means that our alt text is veering towards being long enough to be considered a tedious commitment. In these cases, I like to provide a brief preamble that describes what the snippet is and does, before launching into the code verbatim. Usually, this tends to follow this template or something similar: Language or framework name snippet which demonstrates relevant syntax or technique to provided context Then I reproduce the code in full. This preamble gives screenreader users a handy way to make sense of the code that follows. Crucially, it gives them a handy off-ramp to skip the rest of the alt text if they just can’t be bothered. For example, in a tweet about the