Why would two atoms share instead of steal electrons?
Your clue is the type of atoms involved. When non-metals react with other non-metals, you usually do not get electron handover. Instead, your atoms both pull on the same pair of electrons, and that shared pair becomes the link between them.
A covalent bond happens when your atoms are joined because they are using the same electrons at the same time, rather than one atom giving electrons away completely.
You can think of it like two friends sharing one Netflix password. Neither person fully gives it away, but both get access. In chemistry, that shared access helps each atom reach a more stable outer shell.
A lot of covalent bonding is about the outer electrons only. Your inner electrons stay close to the nucleus and usually do not take part in bonding. The atoms mainly care about getting their valence shell filled, which is why sharing happens in the first place.
One weird but useful fact: even though covalent substances can have strong bonds inside each molecule, the whole substance can still melt or boil quite easily if the forces between molecules are weak. That catches people out in tests.

7 more sections in this topic
Pick this up in your Library: it holds the whole topic, notes, cheatsheet and questions.