Photonic crystals are optical materials that are often fabricated by assembly of particles into periodically arranged structures. However, assembly of lignin nanoparticles has been limited due to lacking methods and incomplete understanding of the interparticle forces and packing mechanisms. Here we show a centrifugation-assisted fabrication of photonic crystals with rainbow structural colors emitted from the structure covering the entire visible spectrum. Our results show that centrifugation is crucial for the formation of lignin photonic crystals, because assembly of lignin nanoparticles without centrifugation assistance leads to the formation of stripe patterns rather than photonic crystals. We further prove that the functions of centrifugation are to classify lignin nanoparticles according to their particle size and produce monodispersed particle layers that display gradient colors from red to violet. The different layers of lignin nanoparticles were assembled in a way that created semi-closed packing structures, which gave rise to coherent scattering. The diameter of the lignin nanoparticles in each color layer is smaller than that predicted by a modified Bragg’s equation. In situ optical microscope images provided additional evidence on the importance of dynamic rearrangement of lignin nanoparticles during their assembly into semi-closed packing structures. The preparation of lignin nanoparticles combined with the methodology for their classification and assembly pave the way for sustainable photonic crystals.