They subtract different things, and the split is by cost behaviour rather than by cost type.
Gross margin is revenue minus cost of goods sold, which is an accounting category. It follows reporting rules and appears on the income statement.
Contribution margin is revenue minus all variable costs, whether or not accounting calls them cost of goods sold. Sales commission, payment processing and shipping usually belong here and often are not in COGS.
The distinction bites when you are deciding whether to take one more order. Contribution margin tells you what that order adds toward covering fixed costs. Gross margin will not, because it may exclude real variable costs and include some fixed ones.