How do I animate Arabic text without breaking the letters?
Arabic letters change shape depending on their position in a word, so splitting a word into single letters breaks the joins. The fix is to animate whole words or whole lines, never single letters.
Steps
- Keep letters joined: do not wrap each letter in its own <span>. A separate element (especially inline-block) breaks the connection.
- Split at the word level and animate each word with a small delay (stagger).
- Keep letter-spacing: 0 on Arabic text. Any spacing pulls letters apart and damages the script.
- Set dir="rtl" and lang="ar" on the element, and start motion from the right.
- For a reveal with no splitting at all, use clip-path on the whole line.
The code
HTML
<h1 class="ar-title" dir="rtl" lang="ar">مرحبا بكم في عالم الحركة</h1>
CSS
.ar-title { letter-spacing: 0; }
.ar-title .word {
display: inline-block;
opacity: 0;
transform: translateY(0.6em);
animation: word-up .6s cubic-bezier(.2,.7,.2,1) forwards;
animation-delay: calc(var(--i) * 120ms);
}
@keyframes word-up { to { opacity: 1; transform: none; } }
/* Option B: whole-line reveal, right to left */
.ar-wipe { animation: wipe-rtl 1s ease-out forwards; }
@keyframes wipe-rtl {
from { clip-path: inset(0 0 0 100%); }
to { clip-path: inset(0); }
}
@media (prefers-reduced-motion: reduce) {
.ar-title .word, .ar-wipe { animation: none; opacity: 1; transform: none; clip-path: none; }
}JavaScript
const el = document.querySelector('.ar-title');
const words = el.textContent.trim().split(/\s+/);
el.textContent = '';
words.forEach((w, i) => {
const s = document.createElement('span');
s.className = 'word';
s.style.setProperty('--i', i);
s.textContent = w;
el.append(s, ' ');
});Note: each word stays in one element, so its letters keep their joins.