Force/Maintain aspect ratio of game/ add black bars on edges/ SOLUTION

Canvas - canvas scaler - UI scale mode - scale with screen size
Canvas - canvas scaler - UI scale mode - screen match mode - expand
Panel - add component - aspect ratio filter - aspect mode - fit in prent
panel - aspect ratio filter - aspect ratio - whatever aspect ratio you want 16/9 or 9/16 or anything
it worked for me. I made game in 9:16 aspect ratio, and when I open in 9:18 and 2:3 aspect ratio display, it does add black bars on edges.
let me know if you have any other method to make it work.

thank you so much personally the fit in parent didnt do what i wanted but changing it to height controlls width made it work perfectly thank you so much!

I search everywhere on the web, spend hours of my time trying to come up with a solution or others, and then find this because you bothered to.