From the Super Mario Wiki
The Countdown Timer is a feature in Super Mario World 2: Yoshi's Island, Yoshi's Island: Super Mario Advance 3, Yoshi's Island DS, and Yoshi's New Island. It was known as just the Timer in the original release of the game. This feature is first explained in the "Welcome To Yoshi's Island" level. If Yoshi hits an enemy, Baby Mario (or any other baby in Yoshi's Island DS) flies away in a bubble and starts crying, and the countdown begins, indicating how long the star powers can protect them. The timer turns red when it falls below ten (three in Yoshi's Island DS). If the Countdown Timer reaches zero, a few Toadies come and steal Baby Mario (or whichever baby is riding on Yoshi's back in Yoshi's Island DS).
In Yoshi's Island DS, the timer is shown in white when the countdown is between 10 to 30 seconds, yellow between 4 to 9 seconds, and red in the last 3 seconds.
The countdown will stop when the Yoshi retrieves the baby, and the Countdown Timer will slowly restore to ten seconds. However, if Yoshi recovers the baby while the Countdown Timer is above ten seconds, no increase is awarded. Stars give Yoshi one more second to the timer, and Middle Rings give Yoshi ten more seconds, up to a maximum of 30. The Countdown Timer also plays a part in determining the score for completing a level, with a point awarded for each second left on the timer.
In Super Mario World 2: Yoshi's Island and Yoshi's Island: Super Mario Advance 3, in addition to collecting individual Stars to increase the timer, the Yoshis can use items called 10-Point Stars (which gives Yoshi ten more seconds when used) and 20-Point Stars (which gives Yoshi twenty more seconds when used).