To produce diffractive or holographic structures in a photolithographic process, an optical projection system enabling structure resolution in the submicrometer range is highly desirable. To ensure that the optical focus of such a system lies on the substrate surface during the whole lithographic fabrication process, an autofocus system able to focus on a depth of field of a few hundred nanometers is usually required. In this work, we developed an autofocus system for spatial light modulator (SLM)-based maskless photolithographic applications. The system is capable of high-precision focusing without affecting the photoresist performance. It is based on contrast measurement combined with focus-pattern illumination to ensure high contrast at the substrate surface. In addition, we evaluated various autofocus algorithms with respect to time efficiency and accuracy to determine suitable focus-pattern and focus-algorithm combinations.