Both are sound repetition devices. Both create music in language. But they operate on different phonetic levels.
Definition: Repetition of the initial consonant sound in closely connected words.
Example: "Peter Piper picked a peck of pickled peppers" — the /p/ sound hammer-strikes at each word's start.
Function: Rhythm, memorability, emphasis, tongue-twister play. Old English verse (Beowulf) built lines on alliteration.
Definition: Repetition of vowel sounds within words—any position, not just initial.
Example: "The cat sat on the mat" — the /æ/ vowel echoes across cat, sat, mat.
Function: Sonic cohesion, mood creation (long vowels = slow/melancholy; short = quick/bright), subtle music without rhyme's obviousness.
Alliteration = consonants at word boundaries. Assonance = vowels inside words. Alliteration marches; assonance hums.
Great writers use both—often simultaneously. "The silken sad uncertain rustling of each purple curtain" (Poe): /s/ alliteration, /ɜː/ assonance, /ʌ/ assonance—a sonic tapestry.