An electronic device may have a display with a transparent layer such as a cover layer. An ambient light sensor may be aligned with an ambient light sensor window formed from an opening in a masking layer on the transparent layer in an inactive portion of the display. To help mask the ambient light sensor window from view, the ambient light sensor window may be provided with a black coating that matches the appearance of surrounding masking layer material while allowing light to reach the ambient light sensor. The black coating may include multiple pigments and may have a flat spectrum to enhance color ambient light measurements made with the ambient light sensor. The black coating may include a polymer binder or other binder that contains multiple pigments. The pigments may include a black pigment, a blue pigment, and an infrared-light-transparent pigment and/or other pigments.