The ions in a solid ionic compound are not randomly arranged. Instead, they have a regular, repeating arrangement called an ionic lattice. The lattice is formed because the ions attract each other and form a regular pattern with oppositely charged ions next to each other.
Remember that the lattice arrangement is giant - for example, a single grain of salt may contain 1.2 × 1018 (1,200,000,000,000,000,000) ions. The lattice arrangement continues in three dimensions. This is why solid ionic compounds form crystals with regular shapes.
The ionic lattice is held together by ionic bonding. In three-dimensional models, the bonds are shown as straight lines between ions. This is to keep things simple because ionic bonding acts in all directions. In the three-dimensional diagram, the ions are shown further apart, but this is only to make the structure clear. The ions are still touching each other, as shown in the previous diagram.
Ionic bonding involves strong electrostatic forces between oppositely charged ions.