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.