Preheat your oven to 425°F.
Grease an 8x8-inch baking dish with butter to prevent sticking.
Melt butter in a large saucepan over medium heat.
Add chopped onion and cook until soft and translucent, about 5 minutes.
Stir in minced garlic and cook for 30 seconds.
Gradually whisk in flour, ensuring no lumps form.
Slowly pour in heavy cream while whisking continuously until the mixture thickens.
Fold in cheddar, Gruyère, and Parmesan cheeses until melted and smooth.
Add salt and black pepper to taste.
Layer sliced potatoes in the prepared baking dish.
Pour the cheese sauce over the potatoes, ensuring full coverage.
Cover the dish with foil and bake for 20 minutes.
Remove foil and bake an additional 30 minutes or until potatoes are tender and the top is golden brown.