In a series of three or more items, use a comma before the final "and" or "or."
Not recommended: I dedicate this book to my parents, Ayn Rand and God.
Recommended: I dedicate this book to my parents, Ayn Rand, and God.
Commas after introductory words and phrases
In general, place a comma after an introductory word or phrase.
Recommended: Finally, only groups that contain parameters appear in this list.
Recommended: Based on the requirements of your game, you can implement this method to update game information.
Commas separating two independent clauses
When a coordinating conjunction (and, but, or, nor, for, so, or yet) separates two independent clauses, insert a comma after the first clause (before the conjunction) unless both clauses are very short.
Not recommended: The libraries not only make feed creation easier but they also ensure that only valid feeds are produced.
Recommended: The libraries not only make feed creation easier, but they also ensure that only valid feeds are produced.
Not recommended: Type your ID, and click OK.
Recommended: Type your ID and click OK.
Commas separating independent from dependent clauses
When an independent clause and a dependent clause are separated by a coordinating conjunction, insert a comma only if the sentence could be misunderstood without one.
Not recommended: Direct-access flags are plain variables, and can be read directly.
Recommended: Direct-access flags are plain variables and can be read directly.
Not recommended: The manager acknowledged the last team member who entered the room and started the meeting.
Recommended: The manager acknowledged the last team member who entered the room, and started the meeting.
Setting off other kinds of clauses
It's often a good idea to set off certain kinds of clauses with a comma or other punctuation, for clarity.
A couple of specific places where commas are a good idea:
- In general, put a comma before the word "which" at the start of a nonrestrictive clause. For more on this topic, see this guide's section on relative pronouns, and Grammar Girl's page on which vs that.
- In general, put a semicolon or a period or a dash before a conjunctive adverb, such as "otherwise" or "however" or "therefore," and put a comma after the conjunctive adverb.
Not recommended: Name of the group which has a maximum length of 200 characters.
Recommended: Name of the group, which has a maximum length of 200 characters.
Not recommended: The variable must have a value otherwise the server returns an error.
Recommended: The variable must have a value; otherwise, the server returns an error.
For information about punctuating numbers, see Commas and decimal points in numbers.