This question already has an answer here:

I know I can create rectangle and put inside a text but is it any easy way to get text with rectangle around it?

marked as duplicate by Scott adobe-illustrator Mar 27 '18 at 19:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.