Igneous rock is formed when magma, molten rock from below the earth's surface, or lava, molten rock that has emerged from below the surface, hardens into a solid state. There are many different kinds of igneous rocks, depending upon where they harden and what materials are contained in them. Igneous rocks form Earth's crust.
Granite is a type of igneous rock. Granite is formed when magma is trapped and cooled within a crack or other opening in pre-existing rock below the surface. Because it cools and hardens slowly, granite has a coarse texture and individual pieces of material can be seen within the rock.
Cooling occurs much more quickly when lava reaches the Earth's surface. As a result, igneous rocks that form on the surface have smoother textures and much finer material. An example of an igneous rock that cooled on the surface is obsidian.
See the link below for more information about how types of igneous rocks are identified and classified.