A composition having nanoparticles of silicon carbide and a carbonaceous matrix or silicon matrix. The composition is not in the form of a powder. A composition having silicon and an organic compound having a char yield of at least 60% by weight or a thermoset made from the organic compound. A method of combining silicon and the organic compound and heating to form silicon carbide or silicon nitride nanoparticles.