Great video about how transistors work.
A transistor is based on semiconductor material, usually silicon, which is ‘doped’ with impurities to carefully change its electrical properties. These n and p-type semiconductors are then put together in different configurations to achieve a desired electrical result. And in the case of the transistor, this is to make a tiny electrical switch. These switches are then connected together to perform computations, store information, and basically make everything electrical work intelligently.