How much space is needed in electrical box for new dimmer switch?
The box fill calculation in NEC 314.16 is per device; there is no code difference in a single gang box for a switch or a duplex outlet or a dimmer. Code treats them all the same, using a 2x the wire size calculation for the largest wire connected to them.

Example: if the box has 2 cables 14 awg with ground there is a total of 6 wires but you only need to count 1 of the grounds. The metal box should have a clamp, so 1 clamp is counted at 1x and 1 device counted at 2x for a total of 8. Now we look up 14 gauge wire per table 314.16B. Number 14 wire is calculated at 2 cubic inches x 8 for a total of 16 cubic inches. The box would need to be 3x2x3.5 per table 314.16.A. I hope this helps your understanding of box fill. Note for 12 gauge wire use 2.25, otherwise the rules are the same.

Also note you need to use the listed size not a measurement of the box the above box is listed as 18 but calculates at 21.