From the Super Mario Wiki
The ! Switch is a switch first seen in Super Mario World. The switch comes in four different colors, Yellow, Green, Blue and Red. Stomping or jumping on the switches activates them. When activated, they turn Dotted Line Blocks into ! Blocks of the corresponding color.
Super Mario series
! Switches first appear in Super Mario World. In each of the four Switch Palaces, there is a giant ! Switch of a different color that turns every Dotted Line Block of the same color into an ! Block of the same color.
In Super Mario 64, three ! Switches appear throughout the game; the red one appears on the Tower of the Wing Cap, the green one appears in the Cavern of the Metal Cap, and the blue one appears in Vanish Cap Under the Moat. Similar to Super Mario World, these cause ! Blocks of the same color to appear in place of the dotted line blocks, allowing players to use the cap power-ups.
In Super Mario 64 DS, a red ? Switch appears on the Tower of the Wing Cap, replacing the three ! Switches of the original game.
The ! Switch also appears in New Super Mario Bros. Wii during the final boss fight with Bowser. During the first half, a small, red ! Switch appears on the other side of the bridge, which causes it to fall and Bowser to be sent into the pit below. Later, at the end of the second half, a large, glowing ! Switch appears that causes the lava to drain and Bowser to once again be sent into another pit.
Orange ! switches appear throughout New Super Mario Bros. 2, usually triggering something that causes coins to appear. ! Switches also appear during the battle with Bowser, in the same way as in New Super Mario Bros. Wii. These switches also appear in the Dry Bowser boss battle in World Star, and only the red switch appears during the Bowser battle in the third course in the Gold Classics Pack. Unlike New Super Mario Bros., the ! switch can only be used once.
An ! Switch also appear in New Super Mario Bros. U. As in the previous game, it can be found in the first half of the battle against Bowser, where its purpose is to enable the axe and destroy the bridge, causing Bowser to fall.
In Super Mario World 2: Yoshi's Island and its remake, Yoshi's Island DS, Yoshi's New Island, and Yoshi's Woolly World, red ! Switches appear. Jumping on them causes the Dotted Line Blocks to transform into red ! Blocks. these allow the Yoshis to cross obstacles such as pits and spikes, or reach otherwise inaccessible areas. Pressing these switches also occasionally causes a warp to a bonus area to appear, indicated by a red arrow above it.
In the Game Boy Advance game Wario Land 4, there are three colored blocks. These "!" Buttons are similar to ! Switches in that they will change from transparent to solid as Wario hits them from below. They are often found in Puzzle Rooms, where Wario can solve a puzzle to gain a Diamond.
! Switches make appearances in several parts of Paper Mario: The Thousand-Year Door. This time, the switches only appear as red or blue. Blue switches can only be used once, normally for opening passages of some kind, while the red switches can be used an unlimited amount of times, and are normally used for moving important objects. However, the red ! Switches found in the Palace of Shadow are the only red ! Switches that can only be used once. They move a wheel, allowing Mario and his friends to get to the Shadow Queen's throne room and crypt.
In Petal Meadows, Mario has to hit two blue ! Switches, called Tandem Switches, simultaneously to activate the Warp Pipe to Hooktail Castle. He accomplishes this by utilizing Koops's hold ability. These switches also exist in Super Paper Mario. The most common of these are blue ! Switches, which generally cause an event to occur. In Chapter 3-3, there are ! Switches that change color between blue and pink when hit; hitting the switch causes the platforms of the corresponding color to appear, while the other platforms disappear.
There are also black and white ! Switches found in the Great Tree. Mario and company push the black switch to reveal four white ! Switches in the room where Mario found the blue key to free the other Punies. Mario has to hit the white ! Switches in this order: Sun, Moon, Puni and Star to retrieve the Super Boots.
Super Paper Mario
In Super Paper Mario, red and blue ! Switches appear in a similar manner to the previous game. In Yold Ruins, there is also a large red ! Switch that appears on the floor by using a standard blue ! Switch, and causes a number of Spiky Tromps that appear by pressing the other switch to fall into a large pit, which allows Mario to access a door.
! Switches appears several times in the Super Mario-Kun manga. In one instance, the switch is used to defeat Rex. In another instance, a Reznor knocks Mario onto a building shaped like the ! Switch. After defeating the Reznor, Mario is shown to be exasperated at a set of invisible blocks, which require a ! Switch to activate.
In Super Mario Advance 4: Super Mario Bros. 3, small, yellow ! Switches appear in some e-Reader levels. These can be carried similarly to the P-Switches of Super Mario World, and when pressed, they turn the Dotted Line Blocks into ! Blocks for several seconds, similarly to in the Yoshi series. Unlike P-Switches, they can be pressed more than once and can even be carried while they are pressed. However, Mario is unable to use Triangle Blocks while carrying an ! Switch.
In Mario Pinball Land, a red ! Switch appears in each world. If Mario hits one of these switches hard enough, eight Red Coins pop out and land in almost every area in the world. Mario has to find the eight Red Coins around the world within the time limit. Hitting the switch is worth 3000 points. Mario can use the switch as many times as needed; once Mario gets all the Red Coins in time, he obtains a Power Star, and the deactivated switch is changed into a Red ! Block. In addition, there is one blue ! Switch during the final battle with Bowser. It can only be activated when at least one of the Thwomps in the room is raised as high as possible, which causes it to glow, and hitting it causes the Thwomp to drop to the floor, temporarily incapacitating Bowser.
In Mario Party 6, a green, yellow, and red ! Switch can be seen inside Orb Shops, although they do not appear to have any function.
Names in other languages