We study Hilbert modular forms in characteristic $p$ and over $p$-adic rings. In the characteristic $p$-theory we describe the kernel and image of the $q$-expansion map and prove the existence of filtration for Hilbert modular forms; we define operators $U$, $V$ and $\Theta_\chi$ and study the variation of the filtration under these operators. In particular, we prove that every ordinary eigenform has filtration in a prescribed box of weights. Our methods are geometric -- comparing holomorphic Hilbert modular forms with rational functions on a moduli scheme with level-$p$ structure, whose poles are supported on the non-ordinary locus. In the $p$-adic theory we study congruences between Hilbert modular forms. This applies to the study of congruences between special values of zeta functions of totally real fields. It also allows us to define $p$-adic Hilbert modular forms "\`a la Serre" as $p$-adic uniform limit of classical modular forms, and compare them with the $p$-adic modular forms "\`a la Katz" that are regular functions on a certain formal moduli scheme. We show that the two notions agree for cusp forms and for a suitable class of weights containing all the classical ones. We extend the operators $V$ and $\Theta_\chi$ to the $p$-adic setting.