The dress code depends on each cruise line
Few issues create as much confusion or contention among cruisers as what to wear to dinner -- and, more importantly, what others wear to dinner. As cruises and cruisers have become more diverse, so has dress -- both what cruise lines ask us to wear, and what we actually wear.
Just about every cruise line has a dress code of some type. (Except for the occasional nudist charter, they all at least agree that clothing is required!) But, from there on, dress codes range from those where dressing for dinner means putting on a clean T-shirt to those where any male passenger not in a tuxedo might as well be wearing nothing at all.
And for every dress code, there are those who try to bend the rules. Those who follow the dress code to the letter often complain of lax enforcement, and truth be told, many cruise lines do seem loath to turn people away, especially for minor infractions. There are plenty of stories of people in shorts and T-shirts when at least a suit and tie is supposed to be required, but lax enforcement isn't universal; at least on some ships, people do get turned away from the dining room.
Unfortunately, it's impossible to predict just how much you'll get away with on a particular night on a particular ship, or exactly what your fellow passengers will actually be wearing. Enforcement really comes down to the whim of whoever is standing at the door at that moment, and as for others' dress, it depends on the passenger mix on your particular cruise. What we can tell you is what each cruise line says you should wear.
Check the dressing codes for most of cruise lines at https://www.cruisecritic.com