I don’t know if I have to play all the strings while strumming for example if I play an e minor than a D Chord while do I have to hit all the strings
Like Trey says, it depends on the chord.
The D chord could be played on just the first three strings, all the notes will be there. It will sound a bit thin, that may or may not be the sound you want. Playing the open D string with it will sound more full. Play the open A string is OK because it’s still a note in the chord, the 5th – you may or may not like the sound, sometimes it will work, other times maybe not. It’s just a different voicing that we could call D/A (D over A).
If you hit the open E string as well then the chord will change, it will become an Dadd9 or Dmadd9 so unless that’s the sound you want then this is the string you want to avoid hitting. Most of the time we’ll just hook our thumb over to dampen the E and A string, this way it doesn’t matter whether we hit them or not, they won’t ring.
If you play all the strings then you might get Gmaj6add9… Dyueger