A comma (,) before such as is required if the clause that follows is not essential to the meaning of the sentence. Do not put a comma before such as if the second clause is essential to the meaning of your sentence.
Add a comma before "such as" if the group of words that follows is not essential to understand the meaning of the sentence.
I love Italian food, such as spaghetti and pizza.
Note that "spaghetti and pizza" are just examples that help us illustrate the basic meaning of the sentence, but they are not essential. If I say "I love Italian food", its meaning would be basically the same.
Do not put a comma before "such as" if the second part of the sentence is essential.
I love food such as spaghetti and pizza.
In this case, the main clause ("I love food") does not provide enough information to understand the meaning of the sentence. The phrase "spaghetti and pizza" is important.
Another example:
Sports such as boxing and rugby are dangerous.
If you take out "such as boxing and rugby", the sentence does not provide the right information. You must omit the comma here because only a number of sports are dangerous, not all of them.
Look at this sentence:
Some sports, such as boxing and rugby, are dangerous.
If you take out "such as boxing and rugby", the sentence is complete and meaningful. Notice that the words "boxing" and "rugby" are not essential. They are just examples that help us illustrate that only some sports (not all) are dangerous. Therefore, you need a comma before such us.
How a Comma Before 'such as' Can Modify the Meaning of a Sentence
Let's examine these sentences:
Insects, such as butterflies and bees, are beautiful creatures.
Insects such as butterflies and bees are beautiful creatures.
The first sentence suggests that all insects are beautiful creatures. In this context, butterflies and bees are just examples of insects, so no comma.
In the second example, by contrast, we are saying that only some insects (butterflies and bees) are beautiful creatures. The second part of the sentence is important to know the type of insect you are talking about.
More Examples
- Markets such as the auto industry and technology are highly competitive.
- Some markets, such as technology and manufacturing, are highly competitive.
- Symptoms such as bloating and constipation may be caused by bacterial overgrowth.
- Alcoholic drinks, such as beer, vodka and rum, are not healthy for your liver.
- Florida is exposed to natural hazards such as intense rains and cyclones.
- Fried foods, such as potato chips and chicken nuggets, are significantly higher in calories than their non-fried counterparts.