A form of potential energy is set up between electric charges analagous to the case when two masses are separated. The easiest way to understand electrical energy is to consider a capacitor.

In a capacitor a potential difference is set up (by a battery) between two conducting plates. This voltage difference V encourages charges to move from one plate to the other. Since like charges repel, work needs to be done to force more of them onto the same plate. The work required dW to move an increment dq of charge is given by¹

dW = dqV
In a capacitor, the total amount of charge that may be moved in this way is proportional to the potential difference V. The constant of proportionality in this case is known as the capacitance C.
q = CV
Substituting this expression for q into the first expression and integrating over q from zero to Q,
W = ∫ (q/C) dq
one obtains
W = Q²/2C = (C/2)V²
The electic field E is given by the gradient of the potential difference. Since this changes linearly over a distance d from one conductor to the other we have E=Vd. Furthermore the capacitance may be written
C = ε A/d
where A is the area of the conducting plates. Thus, the work done is given by,
W= (ε A/2d)(Ed)²
W= (1/2)εE² Ad
Note that the product of the area and the gap between the plates is the volume of the capacitor. Dividing the total energy by the volume yields the electrical energy density uE

uE = (1/2)εE²
In the case of a vacuum, the permittivity ε is that of free space εo. When a dielectric is used between the plates more electrial energy is stored in polarizing the medium.

See also Poynting vector where the electromagnetic energy density is described and magnetic field energy density.

¹ The work done in moving a mass through a gravitational potential is similarly described.