From the Super Mario Wiki
“Ahhhhhh, how romantic! Who would guess that my raunchy little game had such a mood-inspiring vehicle? I'd like to ride my carpet with little miss you-know-who!”
Magic Carpets, also known as Flying Carpets or just Carpets, are magical flying carpets that have appeared in several Mario games in the Mario series.
Super Mario series
Super Mario Bros. 2
They originally appeared in Super Mario Bros. 2, where Pidgits flew on them, and if Mario and the gang defeated the Pidgit that was on the carpet, they would be able to use it like Lakitu's Cloud. This concept may have inspired the ability for players to ride on the clouds, which eventually became possible in Super Mario World. Like them, Lakitu's Cloud also disappeared after a while.
Super Mario 64
They were again found in Super Mario 64, on the stage Rainbow Ride. These carpets were much different from the ones that appeard in the earlier game, most notably, they weren't ridden by Pidgits. These would also not let Mario ride at free will, instead on a pre-set rainbow. They would also not move if Mario was not riding them. They would also not only disappear after a special amount of time, but also if Mario was away too long.
The Super Mario Bros. Super Show!
In the episode "Mario's Magic Carpet", Magic Carpets appeared to have a car-like protrusion on the carpet. However, in the episode "Mario and the Red Baron Koopa", different carpets were seen. King Koopa was seen flying a Magic Carpet that had a warplane protusion, while Mario and Luigi flew around on an normal looking carpets that had a steering wheels. Later on in the episode, Mario, Luigi and Toad used two ordinary Magic Carpets together to construct the wings of a biplane.
Nintendo Adventure Books
A Magic Carpet is used by Princess Toadstool, Mario, Toad and (depending on which route the reader takes) possibly Luigi to enter Iggy Koopa's secret laboratory in Water Land in Leaping Lizards. Three weeks later, some Magic Carpets are used in the first event in the International Mushroom Games, the obstacle course.
In Koopa Capers, Bowser sends a Magic Carpet to Mario Bros. Plumbing to kidnap the Mario Bros., who he is desperate enough to ask to help in the search for his missing daughter. The carpet only captures Luigi (who had at first assumed the carpet was a gift and "a Goomba pattern rug") and proceeds to bring him to Bowser's Castle through the Mario Bros.' personal Warp Pipe to the Mushroom World.
In Brain Drain, if Luigi punches the correct code into the KoopaFone in the Koopa Headquarters cafeteria, he will order a pizza from Magic Carpet Pizzas, a business run by Pidgits who deliver pizzas with their Magic Carpets.
Wario Land 4
In the Game Boy Advance game Wario Land 4, Magic Carpets are found in the level Arabian Night. They are crucial for use if the level is to be completed. Wario can gain height and fly on these carpets by pressing on the D-pad.
Super Smash Bros. series
Super Smash Bros. Melee
Two different Mario-stages featured magic carpets in Super Smash Bros. Melee.
The first one was the Mushroom Kingdom II stage. Pidgits were sometimes flying around the stage in a 2-D form. However, their carpets were in 3-D and, at the times Pidgit was on the screen, could be used as a extra platform. The time was short however and it flied fast, so it was very easy to cause a self-destruct.
The other stage was the Rainbow Ride-themed Rainbow Cruise. Unlike in 64 these could be used as a extra platform and be ride around at free will. Just like in 64, they would also disappear if a player was off or on it for too long. Also, any other player could take the carpet by attacking the one that already has the carpet.
Mario Party series
Mario Party 5
Mario Kart series
Mario Kart 7