What is the inyan concerning finding out the gender of a baby before birth? Is it against Halacha or is it ok? Thank you.
In terms of halacha there is no problem in finding out. In fact, there are several instances in Scripture where a baby’s gender is revealed (such as the birth of Yitzchak, Rivka’s consultation concerning her pregnancy, Shimshon), and there is clearly no problem in this. Furthermore, halachic authorities address instances in which the gender of the baby is known (with regard to which gender of chicken to use for kaparos). Indeed, there is a halachic advantage in finding out gender with regard to Kohanim, for where the baby is a male Kohen, care must be taken that he should not become tamei during a hospital birth.
One sefer (Toras Hayoledes) writes, by way of advice, that it is preferable not to find out, because the Midrash (Bereishis Rabba 65:12, on the verse “as bones in the full stomach”) writes one cannot tell what gender a fetus in its mother’s womb is. The “proof” from the Midrash is of course strained: there is no instruction not to reveal the gender of the fetus, but only a statement that is is hidden — it remains hidden today to all that look with the naked eye.
Others have advised not finding out, because “blessing is only bestowed on something hidden from the eye” (Taanis8b). Yet, it can be argued that the baby is no less “hidden from the eye” after finding out its gender — after all, we already know that it is either a boy or a girl, and Chazal refer to questions of quantification and counting (in business matters) rather than such issues as gender.
[Others advise against finding out because it ruins the surprise!]
Sources: Concerning kaparos (which gender chicken to use), see Piskei Teshuvos 605:2; Kaneh Bosem 2:20. Concerning a pregnant woman entering a cemetary, and hospital births, see Nishmas Avraham YD 371:1, and OC 343:2.