Commas often present difficulties for some because of all the rules you need to remember. The correct use of a comma before such as is easy if you know how to recognize a nonessential clause.
An essential or restrictive clause is a vital part of a sentence because of the meaning it adds to the entire thought. If you remove it, you risk distorting the context and misleading the reader. It is often introduced in a sentence with words like that, who or which. Since it’s part of the meat of the sentence, you won’t see commas around it. The clause is part of its flow.
Nonessential or nonrestrictive clauses are asides that you’ll see in a sentence. Words like which and who signal their presence. On a side note, you should only use the word, that, to introduce essential clauses to be grammatically correct. You can remove nonessential clauses without distorting the meaning of the sentence. That brings us to the comma before such as question.
Using a comma with the phrase, such as, depends on whether or not it introduces an essential or nonessential clause. That may sound easier than it looks because it relies on understanding the overall concept. The problem is that a grammar checker might not flag this type of error. It’s the kind of thing that requires a set of human eyes to make the sentence right.
Now, let’s remove the clause beginning with such as in this example. Foods are my favorite meals. Well, it may be true, but certainly, the context is lost with the removal of the clause. Therefore, it is an essential phrase, meaning there is no comma before such as.
Let’s try another one. If you remove the part after work, the meaning of the sentence remains intact, albeit, without the extra info. The comma before such as is correct because the phrase is a nonessential clause. You can safely delete it if you want without losing the context.
Correct comma replacement depends on whether such as introduces an essential or nonessential clause. If it is nonessential, proper grammar includes the comma. And if it is essential, you don’t need the comma.
An easy way to test yourself is to remove the clause and see if the meaning of the sentence has changed. That’s why understanding the context is crucial for using commas correctly.