Preheat oven to 375°F. Grease a 9x13-inch baking dish with butter or cooking spray.
Arrange sliced potatoes in three slanted rows in the prepared dish. Potatoes should overlap slightly but not be packed too tightly. Tuck onion slices throughout between and on top of potato layers.
Make cheese sauce: Melt butter in medium saucepan over medium heat. Gradually whisk in flour and milk, alternating small amounts and whisking constantly to prevent lumps. Continue until all flour and milk are incorporated.
Bring mixture to a simmer, stirring frequently, until thickened to gravy consistency.
Reduce heat to low. Stir in shredded cheddar, garlic powder, salt, and pepper until cheese is fully melted. Taste and adjust seasoning as needed.
Pour cheese sauce evenly over potatoes and onions, making sure sauce reaches all corners of dish.
Cover pan tightly with aluminum foil. Bake 45 minutes.
Remove foil and sprinkle gruyere and parmesan evenly over top. Return to oven uncovered.
Bake additional 30-45 minutes until potatoes are fork-tender in the center and top is golden brown with crispy cheese spots.
Let rest 10 minutes before serving. Garnish with fresh parsley if desired.