For example, in sodium chloride (NaCl), the sodium ions have a charge of +1 and the chloride ions have a charge of -1. The distance between the ions is relatively small, so the attraction between them is strong. This strong attraction holds the NaCl compound together and makes it a solid at room temperature.
In contrast, in potassium iodide (KI), the potassium ions have a charge of +1 and the iodide ions have a charge of -1. However, the distance between the ions in KI is larger than the distance between the ions in NaCl. This means that the attraction between the ions in KI is weaker than the attraction between the ions in NaCl. As a result, KI is a liquid at room temperature.
Therefore, the attractions between cations and anions hold ionic compounds together. The strength of these attractions depends on the charges of the ions and the distance between them. The greater the charges of the ions and the smaller the distance between them, the stronger the attraction and the more tightly the compound is held together.