Does earnest money go toward closing costs?
Yes. At closing, your earnest money is credited toward the money you owe, which covers both the down payment and closing costs. You do not pay it twice. If you put down $10,000 on a $500,000 home, you bring $10,000 less to the closing table.
On the Closing Disclosure, the deposit shows up as a credit in the table that works out your cash to close. Fannie Mae's guidelines also treat an earnest money deposit as an acceptable source of funds for both the down payment and closing costs, provided the lender can verify where it came from.
So the deposit is not an extra fee. It is part of your total cash, paid early. To see how a given deposit splits against what you owe, use the earnest money calculator, or read earnest money vs down payment.