Mercutio is a foil to Romeo; that is, he is a character who possesses qualities that contrast with those of Romeo.
Whereas Romeo is very serious and melancholy, Mercutio is facetious and glib. When, for example, he talks about Romeo, Mercutio jokes that Romeo is the Petrarchan lover with whom his love object is flippantly set against six women from myths and history. For instance, Mercutio says that compared to Romeo's girl,
Laura was a kitchen slave. Surely she has a better love to make rhymes for her. Dido was shabbily dressed. Cleopatra was a gypsy girl. Helen and Hero were sluts and harlots. (2.4. 13-15)
Further, Mercutio employs lascivious quips about Romeo's relationship to Juliet, joking about Romeo's sexual anatomy as well as Juliet's. This type of language is in sharp contrast to the beautifully poetic language and the language of courtly love that Romeo uses when he alludes to Juliet and her physical features in Act II, Scene 2.
When Romeo arrives in Scene 4, he engages with Mercutio, his friend, and speaks rather lewdly himself, in contrast to his address to Juliet . For instance, Mercutio accuses Romeo of giving his friends "the slip," and Romeo replies that he has had serious business to attend to, but Mercutio jokes,
That’s as much as to say, such a case as yours constrains a man to bow in the hams. [ This is a sexual innuendo that Romeo has been engaged in carnal activity.] (2.4.22)
Romeo returns the joke: "Meaning to 'curtsy'?" (2.4.23) and Mercutio quips, "Thou hast most kindly hit it" (2.4.24), meaning "hit the sexual target."
This dialogue is in sharp contrast to the delicate and metaphoric language employed by Romeo as he speaks to Juliet in the balcony scene. In this dialogue, clearly, Mercutio demonstrates that he is a foil character.
Mercutio's relationship with Romeo is that of Romeo's best friend, but beyond that, Mercutio also serves as Romeo's dramatic foil. Mercutio is the exact opposite of Romeo, and his lewd and humorous nature contrasts against Romeo's serious and devoted nature.
We see Mercutio's humorous nature contrasting against Romeo's when Mercutio makes lewd, sexual jokes, poking fun of Romeo's broken heart and his propensity to fall passionately in love. Lewd humor can be seen in Mercutio's lines:
Without his roe, like a dried herring. O flesh, flesh,
How are thou fishified! (38)
We also see Romeo's and Mercutio's friendship in this scene when they exchange puns. After Mercutio calls Romeo's romantic actions feminine by telling him to "curtsy" as a woman does, Romeo makes a pun out of the word "pump" to refer to both feminine shoes and a sexual insinuation with the line, "Why, then is my pump well-flower'd" (59). Mercutio continues the shoe pun in his lines,
Well said! Follow me this jest not till thou has worn
out thy pump, that, when the single sole of it is worn,
the jest may remain, after wearing, solely singular. (60-62)
Hence, this little punning duel shows us just what good friends Romeo and Mercutio are. It also shows us that Romeo has accepted Mercutio's lewd, humorous, and cynical nature, even if it is the opposite of his own.