The answer to 'how to replace dimmer switch' is to safely disconnect the old dimmer switch and install a new one in its place. This involves turning off the power, removing the old switch, connecting the wires to the new switch, and securing it in the electrical box.
Before starting, make sure to turn off the circuit breaker supplying power to the dimmer switch. Use a voltage tester to confirm the power is off. Then, unscrew the old switch from the electrical box, disconnect the wires, and install the new dimmer switch by connecting the wires and securing it in place. Be sure to follow the manufacturer's instructions carefully.