The inductor opposes any change in current in a circuit by producing an opposing emf also called back emf. As the current changes, there is a potential difference across the inductor and this potential difference or voltage exits only when there is a change in current. If the current is not changing or it is steady, there is no potential difference across an inductor.

The voltage was due to the back emf induced in the coil (inductor) due to the change in current, that is a changing current creates changing magnetic field, which leads to changing magnetic flux and emf is induced in accordance with the Faraday's law. The voltage appears across the inductor due to the back emf caused by the induced electric fields within the inductor.

We know in self-inductance that even if the induced electric fields are not conservative in nature, the voltage across an inductor is real. Do not forget that this voltage we are talking about exists at the time of change in current not when the current is steady.

The voltage across an inductor is

\[V = L\frac{di}{dt} \tag{1}\label{1}\]

The power input to the inductor as a result of this voltage is

\[P = Vi = Li\frac{di}{dt}\]

Then the energy being delivered to the inductor for small time \(dt\) is \(dU = Pdt\) and

\[dU = Lidi\]

The total energy delivered to the inductor when the current changes from 0 to I is

\[U = L\int_0^I idi = \frac{1}{2}LI^2 \tag{2}\label{2}\]

You know from the the magnetic field of a solenoid is \(B = \mu_0nI\), and \(I = B/\mu_0n\). Let's determine the self-inductance of a solenoid. You know that

\[L = \frac{N\Phi_B}{I}\]

Here the difference between \(i\) and \(I\) is that \(i\) is the changing current but \(I\) is the final stable current and it is steady. For a solenoid, \(\Phi_B = BA = \mu_0nIA\), then

\[L = \mu_0nNA = \frac{\mu_0N^2A}{l}\]

where \(l\) is the length of the solenoid, and substituting the value of \(L\) and \(I\) into Equation \eqref{2}, we obtain the expression of total energy input to the inductor, so

\[U = \frac{B^2}{2\mu_0}V \tag{3} \label{3}\]

where \(V\) is the volume of the solenoid \(V = Al\). The above expression is derived for a special case of a solenoid, but it is valid for any magnetic field configuration. In case of an inductor, this energy is stored in the magnetic field of the inductor with steady current \(I\). As the current decreases from \(I\) to 0, this energy is released again. The magnetic energy density \(\mu_B\) is the magnetic field energy per unit volume, that is

\[ \mu_B = \frac{B^2 }{2\mu_0}\tag{4} \label{4}\]

As the current increases, the potential differnce is created across inductor due to induced electric fields within it (the changing magnetic field of the inductor induces it), and the energy is delivered to the inductor. As the current is stable and steady, there is no voltage across inductor and the current will simply pass without any energy being delivered to the inductor.

As the current that sustains, the magnetic field that sustains the current also decreases. The decreasing magnetic field causes the change in flux, and emf is again induced in a direction to oppose the decreasing current. So an inductor wants to keep the current stable.

When the current is interrupted suddenly by opening the switch, the collapsing magnetic field leads to large voltage across inductors. This causes the arc across switch contacts. Inductive spiking, and ignition coils can generate thousands of volts. That's possible due to the energy stored in the magnetic field.