Preheat oven to 375°F. Grease a 2-quart baking dish (8x12 works well) with butter or nonstick spray.
Arrange potato slices in three slightly slanted rows, leaving space so they aren’t packed too tightly. Tuck onion slices between and on top of the potatoes.
Make the sauce: In a medium saucepan over medium heat, melt the butter. Whisk in the flour and cook for 1 minute. Slowly whisk in the whole milk until smooth and thickened, about 3–4 minutes.
Reduce heat to low and stir in cheddar cheese, onion powder, rosemary, salt, and pepper. Taste and adjust seasoning if needed.
Pour the sauce evenly over the potatoes and onions. Cover tightly with foil and bake for 45 minutes.
Remove foil, sprinkle Gruyere and Parmesan evenly over the top, then return to the oven for 30–40 minutes, or until the potatoes are fork-tender and the top is golden brown.
Let rest 10 minutes before serving. Garnish with fresh parsley.