Preheat Oven:
Preheat oven to 375°F (190°C). Grease a 9x13-inch baking dish with butter.
Prepare Potatoes:
Slice potatoes evenly (about ⅛ inch thick). Place in cold water to prevent browning, then drain and pat dry before layering.
Make Cream Sauce:
In a saucepan over medium heat, melt butter.
Whisk in flour and cook for 1–2 minutes to form a roux.
Slowly pour in milk and heavy cream, whisking constantly.
Add garlic, salt, and pepper.
Simmer 4–5 minutes until slightly thickened and able to coat the back of a spoon.
Layer Potatoes:
Arrange one-third of potatoes evenly in the baking dish.
Top with some sliced onion and pour one-third of the sauce over the layer.
Repeat layers two more times.
If using cheese, sprinkle between layers or on top.
Bake Covered:
Cover tightly with foil and bake for 45 minutes.
Bake Uncovered:
Remove foil and bake an additional 25–30 minutes, until golden brown and bubbling.
Rest & Serve:
Let rest for 15 minutes before serving to allow sauce to thicken fully. Garnish with fresh thyme if desired.