Stars in constellations appear close together from our perspective on Earth, but they are actually vastly separated in space. They are just in the same line of sight from our point of view.
Think of it like this: if you hold your hand out in front of you and look at it, your fingers might appear to be close together. But if you were to move your hand further away, those fingers would look even closer together. The stars in constellations are like those fingers, but they are light-years apart, not just inches!