Savvas Stephanides | Unpezable Games πŸ‡¨πŸ‡ΎπŸ•ΉοΈ Profile picture
I'm a dev. Unpezable Games https://t.co/MRmO6Zyuwb

Sep 1, 2020, 10 tweets

The problem with the "typewriter effect" on your website and how to fix it.

(Thread) πŸ§΅πŸ‘‡

#100DaysOfCode #CodeNewbie #accessibility

So you want to show off your portfolio website and you want to add some fancy graphics to show off your Javascript skills. What better way than by adding a fancy "typewriter effect" to show the world your multi-faceted personality?

It's nice, sure! But there's a problem. And it has to do with accessibility.

Simply put, blind people visiting your website with screen readers, just can't see what the hell you've written on that section.

Here's an example, using VoiceOver on Safari for iOS:

Transcript: "Coffee underscore. Heading level 1"

That is pretty horrible! And it's probably already on your website! How do we fix it? Let's see!

Let's say the HTML code for your typewriter effect:

<h1 id="typewriter-effect">
<span id="text"></span>
</h1>

You then write some CSS for the colouring, and then some Javascript to actually create the effect

Example: codepen.io/SavvStudio/pen…

If you use a screen reader, it would result in the effect shown above. To fix this we're going to use two ARIA attributes: "aria-label" and "aria-hidden":

aria-label - to make the screen reader say what we want
aria-hidden - to make the screen reader skip the typewriter text

So your new HTML would look like this:

<h1 id="typewriter-effect" aria-label="Developer, designer and coffee addict">
<span id="text" aria-hidden="true"></span>
</h1>

And this is what it sounds like to screen reader users

Transcript: "Developer, designer and coffee addict. Heading level 1"

A lot better! Try it for yourself and see that your website will become more accessible as a result!

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling