The emergence of the microbiota-gut-brain axis has opened new avenues for improving sleep quality. Recent studies have revealed a close relationship between insomnia and the gut microbiome. Chinese herbal medicines and their active components can alter the relative abundance of sleep-related gut microbiota by reversing dysbiosis in the gut microbiome. Improving sleep quality through the regulation of the gut microbiota using herbal medicine and its active components has become a highly promising therapeutic strategy. This article elucidates how the gut microbiota modulates sleep quality via the intricate communication network of the gut-brain axis. It also reviews the latest research on utilizing herbal medicine and its active components to regulate the gut microbiota for enhancing sleep quality. Additionally, it provides insights into the potential of herbal medicine and its active components in improving sleep quality through the modulation of the gut microbiota.