From the Super Mario Wiki
Beat Blocks are a rare type of block found in Super Mario Galaxy 2, Super Mario 3D Land, and Super Mario 3D World. As their name implies, Beat Blocks are recognized for alternating between solid blocks and intangible outlines of various colours to the beat of in-game music. Because of this, Beat Blocks function as both platforms that Mario or Luigi safely can stand on when solid, or as deadly pitfalls in their "vanished" state. Depending on the game, both the physical appearance and functions of Beat Blocks differ.
Beat Blocks are first seen in Super Mario Galaxy 2, appearing exclusively in the Beat Block Galaxy. In this appearance, all Beat Blocks are cube-shaped, and alternate between yellow and green. Mario or Luigi must traverse this galaxy, which is made up almost entirely of Beat Blocks, with caution and good timing. The player's Wii Remote will also beep three times before the Beat Blocks alternate. Due to the effects of the Double Time Comet, the Star mission "Silver Stars in Double Time" causes the Beat Blocks to alternate at four times their regular speed (despite the mission's name).
Beat Blocks return in Super Mario 3D Land, appearing in World 6-4, Special 3-5 and Special 7-2 (which is a revise of World 6-4, only with a Cosmic Clone chasing Mario or Luigi). In this appearance, Beat Blocks come in an assortment of shapes, and are now red, yellow and blue. In World 6-4 and Special 7-2, all three colors will appear one-by-one, then vanish in the same manner, leaving periods where all or none of the Beat Blocks will appear solid. However, in Special 3-5, the blocks alternate between one colour each time.
Beat Blocks return once again in Super Mario 3D World as they appeared in Super Mario Galaxy 2, but with the name Beep Blocks. They alternate between blue and red-colored blocks. Later levels also include Beat Blocks in double time, as the game calls them, Blast Blocks. When they are in double time, the frequency of alternating between different blocks is the same as the frequency of beat blocks' alternation under the orbit of the prankster comet in Super Mario Galaxy 2. Interestingly, the double time Beat Blocks also appear in levels where the song has different BPM, but they still alternate in the beat of the original song's BPM (from Beep Block Skyway and Blast Block Skyway).