Periods and commas belong inside quotes in American English
Published on in English
Like so: "The name's Bourne," the man said, "JSON Bourne." Also when quoting single words, like "nibbles," "gronk" and "fleebles."
Why? Because it's a rule. Some sources:
- Quotation marks on The Punctuation Guide
- Does Punctuation Go Inside Quotation Marks? on YourDictionary
- Why do periods and commas go inside quotation marks in MLA style? on MLA Style Center
If you are not convinced, consult your favorite style guide.
I write mainly American English. I avoid mixing in other flavors, like British English, to keep my English consistent.
Place periods and commas outside the quotes if placing them inside the quotes could make the text ambiguous or lead to errors, e.g. when quoting user inputs.
The password is "hunter2."
The above is ambiguous: does the password include the period or not?
Compare with this:
The password is "hunter2".
The above is unambiguous and thus preferable.
Sometimes it's better to change the sentence structure to avoid this problem.
I don't know if this exception is actually allowed in American English, but it's common sense.