Styrofoam floats in water because it is less dense than water. This principle applies to all objects. That is, anything less dense than water will float, while anything more dense will sink.
When an object is placed in water, it displaces an amount of water equal to the volume of the object. If you imagine the volume of displaced water before the displacement takes place, it is clear that the water is supported by the water around it. That is, the "chunk" of water displaced was already being held up by the rest of the water. This water was being held up by the force of the water below and around it.
This force, when applied to an object which replaces the displaced "chunk" of water, is called the buoyant force. So, if an object is more dense than water, this means that it will weigh more than the water it displaces, and the buoyant force will not be able to support it. On the other hand, if, like styrofoam, the object is less dense than water, it will weigh less than the displaced volume of water and the buoyant force will support it.