The four characters combine to form a historical allusion. In the ancient state of Chu, during military reviews, the army was divided into formations. The most elite soldiers, carrying banners decorated with cattail stalks, were positioned at the very front. Therefore, to have your “name listed (列) in the front (前) cattail (茅) section” meant you were recognized as one of the best and most elite.
名列前茅 is deeply tied to China's highly competitive culture, particularly in education. The concept echoes the historical imperial examination system (科举, kējǔ), where scholars from across the empire competed fiercely for a limited number of government positions. To succeed was not just a personal victory but a great honor for one's entire family and hometown.
This idiom is formal and is used to confer high praise. It is most appropriate in written language or formal speech.
The connotation is always positive and carries a sense of admiration and respect.