- Don’t use a comma before while when you mean “during the same time.”
- Do use a comma before while when you mean “whereas” or “although.”
When while is used as a conjunction, it has two meanings. One meaning is related to time. In the temporal sense, while describes something that is happening at the same time as something else. The other meaning of while indicates a contrast. In this sense, it means “whereas” or “although.”
No Comma With While Means “At the Same Time”
Don’t use a comma before while when you’re talking about two things happening at the same time.
Comma With While Means “Whereas” or “Although”
Use a comma before while in the middle of a sentence when you mean “whereas” or “although.”
While at the Beginning of a Sentence
When while is the first word of your sentence, you obviously shouldn’t add a comma in front of it. But if you’re using while to mean “whereas,” you still need to put a comma somewhere. Put it at the end of the clause that while introduces. The comma should go between the things that are happening at the same time.
from Grammarly Blog https://www.grammarly.com/blog/comma-before-while/