The tag, which would appear on the packaging, also could be used to determine if medications and other perishable products were still active or fresh, scientists said.
"This tag, which has a gel-like consistency, is really inexpensive and safe, and can be widely programmed to mimic almost all ambient-temperature deterioration processes in foods," said Chao Zhang, the lead researcher of the study.
Use of the tags could potentially solve the problem of knowing how fresh packaged, perishable foods remain over time, he added.
A real advantage, Zhang said, is that even when manufacturers, grocery-store owners and consumers do not know if the food has been unduly exposed to higher temperatures, which could cause unexpected spoilage, "the tag still gives a reliable indication of the quality of the product."
The tags, which are about the size of a kernel of corn, would appear in various colour codes on packaging.
"In our configuration, red, or reddish orange, would mean fresh," said Zhang, from Peking University in Beijing, China.
"Over time, the tag changes its colour to orange, yellow and later green, which indicates the food is spoiled," said Zhang.
The colours signify a range between 100 per cent fresh and 100 per cent spoiled.
If the label says that the product should remain fresh for 14 days under refrigeration, but the tag is now orange, it means that the product is only roughly half as fresh.
In that case, the consumer would know the product is edible for only another seven days if kept refrigerated, Zhang said.
Researchers developed and tested the tags using E coli (food-spoiling bacteria that cause gastrointestinal problems) in milk as a reference model.
"We successfully synchronised, at multiple temperatures, the chemical evolution process in the smart tag with microbial growth processes in the milk," said Zhang.
The tags could also be customised for a variety of other foods and beverages.
The tags contain tiny metallic nanorods that, at different stages and phases, can have a variety of colours: red, orange, yellow, green, blue and violet, Zhang said.
"The gold nanorods we used are inherently red, which dictates the initial tag colour," he said.
The finding was presented at the National Meeting & Exposition of the American Chemical Society (ACS) in Dallas.