Before we discuss opto-isolation we need to define simple isolation. What do we mean when we say something is electrically isolated from something else ? In it's simplest interpretation it means there is no electrically conductive path between the two "somethings".
The most common example of this is a switch. When you switch something off you separate two conducting pathways preventing the flow of electrical current. A typical light switch does this by moving two metallic strips apart leaving an "isolating" air gap between them. However , even in this simple example there are two levels of isolation. Consider the circuit that powers a light bulb
via a switch.

The electrical circuit between the power source and the light bulb forms a circuit running from live to neutral via the switch and the light. To stop the flow of electrical current, and therefore turn off the bulb, it is only necessary to break the circuit in one position. This is usually between the live terminal and the bulb. But notice, however , that the
neutral is still connected to one side of the bulb. If you were to accidentally touch this contact on the bulb you would be touching the neutral side of the main power source. Although this is normally at the same voltage potential as earth, it can still pose a risk and cannot be considered safe. If we were to replace the switch with one which break both sides of the circuit the light bulb would obviously still turn off, but we would be much safer. The light bulb contact would
be completely disconnected from the power source. i.e.. ISOLATED. This type of switch is called a double pole (or isolator).

Creating an air gap in a circuit obviously stops the flow of electrical current by introducing an electrical insulator (air) into the circuit. This , however, is not the end of the story. What about high voltages ?
Air is only an insulator below it's breakdown voltage. This is the voltage where air loses it's insulating properties and starts to conduct. Typified by sparks and visible arcing jumping across the air gap. The voltage at which air "breaks down" is approximately 30,000 volts per centimetre. So you can see that it is quite large and you could be forgiven for thinking that is is so large that you can safely ignore it in most domestic situations. It is true that such high
voltage are uncommon , even in fault situations, but they can occur from a variety of reasons. for example, when you connect an inductive device to a circuit there is a large voltage developed (called a back EMF) whenever you break the circuit. It is analogous to inertia in the mechanical world. i.e. the flow of electrons tries to continue even after the circuit is broken and build up a large voltage across the gap. (specifically and to be technically correct, it is the collapsing magnetic
field created by the flow of current through an inductor that causes this effect, but the analogy offers a better "feel" for what is happening). When these larger voltages occur they can easily damage the circuits that are connected to them. i.e.. your computer. The occurrence of such "spikes" in voltage are not confined to switch-off since there are usually commutation (switching) of currents at regular intervals with most simple motors, solenoids and similar devices.
For this reason it is safer and generally accepted practice to connect external devices, especially higher power rated ones, via some form of permanent isolation.

So how do we let controlling voltages through to the device and prevent returning spikes ? The answer is LIGHT. The problem is that we need to communicate (in the most general sense of the word) the
logic level 0 or 1 to an external device to say on/off without actually connecting to it.
Imaging someone with a torch (flashlight) signalling to another person who operates a switch which in turn operates the device. There is no electrical connection between them and therefore no risk of returning voltage spikes but the control works perfectly albeit with a slight delay based on the response time of the switch operator to seeing the light. In electronics this techniques
is used encapsulated inside a small component called an OPTO-ISOLATOR. Inside the component there is the equivalent of an LED (light emitting diode) and a light sensor. The input circuit is usually connected to by pins on one side of the "chip" with connections to controlled devices on the other side. This separation across a component which is basically an insulator with a gap in the middle across which only light passes forms the basis of electrical isolation,
Typically voltages have to exceed 1000v to "bridge" this gap. With these components in place ON ALL OF YOUR CONNECTIONS to the outside world , the danger of an external device causing damage to your PC is greatly reduced. It is important to realise that if there is a single directly connected output from your PC to the external circuitry it would make all of your isolation efforts useless since the voltage spikes would find the path of least resistance and circumvent your
isolation components.