Provided are: an ink-repellent composition exhibiting excellent ink repellency and UV/O3 resistance; a hardened film and partition wall, the upper surfaces of which exhibit excellent ink repellency and are capable of maintaining excellent ink repellency even after undergoing an UV/O3 irradiation treatment; and an optical element in which ink can be evenly applied within dots. The ink-repellent composition includes: a first compound which is a partial hydrolysis condensate of a mixture including a first hydrolysable silane compound comprising a hydrolysable group and a fluoroalkylene group and/or fluoroalkyl group; and a second compound that has a hydrocarbon chain as the main chain, has a side chain containing a fluorine atom, and has a mass-average molecular weight (Mw) of 100-1,000,000.