When you complete all of your degree requirements, you are in your grace period.
You cannot travel outside the U.S. and reenter with your F-1 or J-1 student visa during your grace period. Your grace period is time for you to make plans to leave the U.S. or take action on your immigration record. You can travel within the U.S. during this time, but if you depart the U.S. you will need to apply for another visa status, such as a visitor visa.
If you have applied for OPT or you have your EAD card, review the Travel & OPT risks and recommendations. OPT is not a separate visa category. It is still an F-1 student visa.