Don’t use a comma before while when you mean “during the same time" but you can use it 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.”
Here’s a tip:
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/simultaneously.
Comma With While Means “Whereas” or “Although” while "while" without comma means "at the same time".
*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.
Ex.: while driving past them, he developed a headache.
The comma should go between the things that are happening at the same time.
BASICS
I decided to take a nap under my desk while everyone else was in the meeting.
Correct✅
I decided to take a nap under my desk, while everyone else was in the meeting.
Incorrect ❌
Let’s order the curtains while they’re still on sale.
Correct ✅
Let’s order the curtains, while they’re still on sale.
Incorrect❌
I prefer chocolate cake, while my sister prefers key lime pie.
Correct✅
I prefer chocolate cake while my sister prefers key lime pie.
Incorrect❌
The price of eggs is rising, while the price of milk has stayed the same.
Correct✅
The price of eggs is rising while the price of milk has stayed the same.
Incorrect❌
While my sister prefers key lime pie, I prefer chocolate cake.
Correct✅
While the price of milk has stayed the same, the price of eggs is rising.
Correct.✅