I have often heard that one should not wear shorts while davening. This makes intuitive sense to me that we should do this out of respect. But is there any halachic reasoning behind this? Is it absolutely forbidden to wear shorts while davening, or is this just something that is nice to do?
My Rabbi pointed out to me a prohibition on wearing shorts in synagogue, in a book on halacha.
I don't recall if it mentioned the following, which I've heard. In the case of kibbutzim, where anyways people are wearing shorts as they work outside in the fields, and they weren't required to go home to change before praying; even the shaliach tzibur could wear shorts.
On another occasion, I saw a friendly acquaintance wearing shorts in synagogue and mentioned that I'd been told it wasn't allowed, so he might want to check with his rabbi as to what to do. He responded by saying that it's short shorts that are prohibited, but his were knee-lengths and his rabbi said it was OK albeit not preferable in the first place.
Also: I thought about the "before the King" analogy and have the following issue with it. We're also "before the King" when we go anywhere, because He Is everywhere. So by that reasoning you couldn't wear shorts ever, and yet we find that there's an obligation to teach one's kids to swim, which obviously requires wearing shorts. If you were to respond by differentiating between a synagogue as being especially holy, that's a good point but I don't think it fully answers the issue. It's like someone who pointed out that men don't need to shower 3x/day just because they pray 3x/day.
Emotionally I'd like to be able to wear shorts in synagogue, intellectually I feel the holiness of the place bars that possibility. Don't test me for intellectual honesty :P
Interpreting from Mishna Berura in 2:1 , Irrespective of davening You should never wear any clothing which does not extend beyond your knees. The shape of your body also should not be discernible to the onlookers. Ideally all coverable parts of your body should be covered at all times not just davening.
there is a principle that things which can be derived from reason via "kal v'chomer" (major to minor logical inference) are obligatory even if they are not explicitly written in the torah.
The Talmud in Pesachim 75b discusses the prohibition of bringing coals which make too much smoke for the incense offering. There it says: "For that you don't need a verse, [to prohibit it] since before a flesh and blood king, one would not do this, how much more so before the King of kings, the Holy One blessed be He."
Hence, the torah does not write things which one can derive from reason even though they are obligatory. Just like it doesn't say anywhere that you can't daven while holding a cat.
So, to answer the question, under normal circumstances and for someone with some degree of intelligence as to Who he is praying to, it would seem to be forbidden by the above kal v'chomer.
The Shulchan Aruch (Orach Chaim 91:5) seems to be of the opinion that one should not wear shorts while davening if that would seem inappropriate:
לא יעמוד באפונדתו [טאסקא בלעז] ולא בראש מגולה ולא ברגלים מגולים אם דרך אנשי המקום שלא יעמדו לפני הגדולים אלא בבתי רגלים:
A person should not stand with their money-belt ["taska" in the language of this country] on, or with an uncovered head or uncovered legs, if it is the practice of the people of that place not to stand in front of important people unless their legs are covered.
However, the Mishnah Berurah (91:13) seems to grant a little leeway:
מיהו אם הבגד ארוך שחופה את הרגלים או בארצות החמין מאוד שעומדי' שם ג"כ בפני גדולים יחף אין לחוש אפילו הבגדים קצרים ונראין הרגלים
However if his clothing is long that it covers his legs, or in places of very warm weather and one would stand in front of important people even barefoot, one need not worry even if the clothes are short and one's legs can be seen
R' Ovadya Yosef in Yechaveh Da’at IV:8 (quoted in yeshiva.co articles here and here) also seems to allow wearing shorts in certain circumstances-- namely, in places and for people where shorts are commonplace (ex: kibbutzim, or kids during the summer), one is permitted to daven in shorts- though a person in shorts should not be chazzan.