From the Super Mario Wiki
Gravity Arrows are objects found in Super Mario Galaxy and Super Mario Galaxy 2. They can be found in several galaxies, including Battlerock Galaxy, Dreadnought Galaxy and Clockwork Ruins Galaxy. These arrows point in the current direction of gravity. When Mario uses his spin within their vicinity, the arrows will change direction and color, along with the direction of gravity.
Sometimes, by using other techniques, it is possible for Mario to progress without hitting a Gravity Arrow.
Gravity Arrows can also be found in Luigi's Mansion. In this game, if Luigi steps on one he will automatically start walking in the ceiling. If he walks over another one, he will start walking in the floor again. They can only be found in the Tea Room and in the Cellar.