Motivated by the recent synthesis of layered hexagonal aluminum nitride (h-AlN), we investigate its layerand strain-dependent electronic and optical properties by using first-principles methods. Monolayer h-AlN is a wide-gap semiconductor, which makes it interesting especially for usage in optoelectronic applications. The optical spectra of 1-, 2-, 3-, and 4-layered h-AlN indicate that the prominent absorption takes place outside the visible-light regime. Within the ultraviolet range, absorption intensities increase with the number of layers, approaching the bulk case. On the other hand, the applied tensile strain gradually redshifts the optical spectra. The many-body effects lead to a blueshift of the optical spectra, while exciton binding is also observed for 2D h-AlN. The possibility of tuning the optoelectronic properties via thickness and/or strain opens doors to novel technological applications of this promising material.