when molten material is underground it's called magma. Magma is below Earth's surface so it cools slowly. The slower it cools, the more time the crystals have to expand. Big crystals result in a coarse texture.
When magma reaches the surface it becomes lava, rocks formed from lava (lava is on the surface) cool faster leaving the crystals with very little time to expand. small crystals result in a fine texture.