The 19-time Grand Slam champion, who was born in Basel, received the title from the medical faculty at the uni.
They praised him for his role in increasing the international reputation of Basel and Switzerland at a graduation ceremony on Friday.
Roger Federer was not able to be at the ceremony in person but he did record a video message.
In it he expressed his appreciation and said the honorary doctorate made him as happy as any Grand Slam title.
Explaining why they were acknowledging Federer, the university said he was a role-model athlete who encouraged people worldwide to be more physically active. He also contributed to the promotion of a healthy lifestyle.

vCard.red is a free platform for creating a mobile-friendly digital business cards. You can easily create a vCard and generate a QR code for it, allowing others to scan and save your contact details instantly.
The platform allows you to display contact information, social media links, services, and products all in one shareable link. Optional features include appointment scheduling, WhatsApp-based storefronts, media galleries, and custom design options.
The uni highlighted the 36-year-old’s engagement for children in Africa through his charitable foundation too.
Federer’s award was one of seven honorary doctorates given to outstanding members of society at the university’s Dies Academicus.
The honour is yet more recognition that Federer has received this month.
He finished no 2 in the ATP Rankings and received three awards in the 2017 ATP World Tour Awards.
Those include the ATPWorldTour.com Fans’ Favourite, Stefan Edberg Sportsmanship Award and Comeback Player of the Year.