Living organisms tend to evolve various naturally photoprotective mechanisms to avoid photodamage. Among them, polydopamine (PDA) is an effective sunscreen, a mimic of melanin, which is the main functional component of the photoprotective system of human skin. However, the concerns of its dark color, skin penetration and photoprotective efficiency remain yet to be solved. Herein, we have constructed melanin-inspired nanocomposite hydrogels (CS-PDAh-GP-HA) for photoprotection, in which PDA was prepared as hollow nanoparticles (PDAh NPs) and entrapped in a physically cross-linked hydrogel (CS-GP-HA) formed by chitosan (CS) and hyaluronic acid (HA) using β-glycerophosphate (β-GP) as a modulator. The CS-PDAh-GP-HA hydrogels exhibit a shear-thinning flow behavior with an elastic modulus of 300 Pa with the gel-sol transition temperature maintained at about 37 °C simply by adjusting the β-GP content in the hydrogels. The CS-PDAh-GP-HA hydrogels also possess excellent resistance toward skin penetration. The photoprotective performances of CS-PDAh-GP-HA hydrogels were evaluated by the determination of sun protection factor (SPF) and in vitro UVA protection efficacy (UVAPE) along with UV–Vis spectroscopy. Compared with the TiO2 nanoparticles in CS-GP-HA hydrogel, the CS-PDAh-GP-HA hydrogels show stronger shielding ability in both UVA and UVB regions. When protected by the CS-PDAh-GP-HA hydrogels, the cell viability of NIH-3T3 fibroblasts increases to 96% while it was only 14% in the case of non-protecting group. These results suggest that the CS-PDAh-GP-HA hydrogels could efficiently shield the UV irradiation and protect the skin from photodamage. This work introduces PDA-based nanocomposite hydrogels with safe, biocompatible and photoprotective properties, and provides a melanin-mimicking photoprotection system for the application in sunscreens.