If you have decided a capacitor is bad and want to replace it you'll need to not only get one of similar electrical value, but also physical dimensions. Through hole, SMD, and rectangular SMD parts are all measured physically in different ways however. Knowing how to measure them will make getting proper fitting replacements much easier. I highly recommend getting a set of calipers to measure with instead of using something like a ruler. Inexpensive digital calipers will be good enough for most measurements you need to make.
The most important measurement for through hole parts is the "pitch" which is the distance between the pins. This is measured directly from one pin to the other. Radial capacitors also need their diameter and height measured. You can probably get away with a different height but it can matter if it's a complex and densely packed device. The size of the diameter and the pitch of the pins aren't always guaranteed to be related but there are common size and shape capacitors where these values are likely to be used by many parts. The height can vary a lot more.
You may find when ordering replacements that you can only find smaller sizes than when you are removing. As long as you are able to match the electrical values this won't matter too much as the pins coming from the capacitors can be bent out a bit to compensate for this.
For can type SMD caps you really only need to worry about the diameter, the position of the pads is always relative to that. These are much more standardized for the size and the pads are usually slightly oversized on a PCB and can accommodate slightly different parts. The height still needs to be checked but these capacitors are usually shorter.
There are specific standard sizes for these parts. One of the most common for example is 0603, but these come in metric and imperial sizes. These sizes can be cross referenced between the two so you can get all sizes available in either. It is possible to measure these and look up what the sizes are, you will want to use a look up table to determine what size code your part is. There are also physical guides you can get to hold them up against to instantly see the size. They are different enough that if you work with enough of them you'll be able to recognize the sizes by eye eventually.