The key difference between optical storage media, such as CDs and DVDs, and magnetic storage media, such as hard drives and old-fashioned floppy disks, is in how computers read and write information to them. One uses light; the other, electromagnetism.
Computers are binary, meaning that for them to understand information, it has to be boiled down to a series of digits, each of which is a 1 or a 0. Storage media use different methods of representing those digits.
Magnetic storage uses disks coated with a magnetic material. Each tiny bit of the disk carries a magnetic charge; the direction of that charge determines whether it represents a 1 or a 0. Optical storage, meanwhile, uses disks made of reflective material; how each bit reflects light–or doesn't reflect it–determines whether it's a 1 or a 0.
Video of the Day
Magnetic storage devices use "read/write heads," electromagnets that detect (read) or change (write) the magnetization patterns on the disk. Optical storage devices use lasers to read the reflections in the disk or "burn" the data pattern into the disks.
In general, it's faster and easier to write data to magnetic storage media. However, data stored on optical media tends to be more durable.