Skip to content

Instantly share code, notes, and snippets.

@dominikwilkowski
Last active May 11, 2025 00:54
Show Gist options
  • Save dominikwilkowski/c8d31b676470c1fac180e8f8172d3577 to your computer and use it in GitHub Desktop.
Save dominikwilkowski/c8d31b676470c1fac180e8f8172d3577 to your computer and use it in GitHub Desktop.
Accessible emoji react/emotion component
<!DOCTYPE html>
<html>
<head>
<link crossorigin="anonymous" media="all" rel="stylesheet" href="styles.css" />
</head>
<body>
<span role="img" aria-label="A magic wand" tabIndex="0" class="emoji">🪄</span>
</body>
</html>
.emoji {
position: relative;
}
.emoji:focus:after,
.emoji:hover:after {
content: attr(aria-label);
position: absolute;
display: block;
z-index: 1;
bottom: 100%;
left: 0;
font-family: var(--font-mono);
font-weight: normal;
padding: 0.6em 0.75em 0.5em 0.75em;
border-radius: 0.5em;
box-shadow: 0 0 0.2em rgba(0, 0, 0, 0.5);
background-color: rgba(0, 0, 0, 0.85);
color: #fff;
text-align: center;
font-size: 0.8rem;
opacity: 0;
animation: fadeIn 0.1s ease-out 0.3s 1 forwards;
white-space: nowrap;
}
@media print {
.emoji:after {
content: " (" attr(aria-label) ") ";
font-size: 0.75em;
font-weight: normal;
}
}
@media (prefers-reduced-motion) {
.emoji:focus:after,
.emoji:hover:after {
animation: fadeIn 0s ease-out 0s 1 forwards;
}
}
@keyframes fadeIn {
from {
bottom: -0.5em;
opacity: 0;
}
to {
bottom: 100%;
opacity: 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment