The Continental Congress voted to declare the American colonies independent on July 2, 1776.
The vote approved the Lee Resolution, introduced by Virginia delegate Richard Henry Lee. It stated that the United Colonies should be free and independent states, ending their political connection with Great Britain. Congress then turned to a written explanation of that decision: the Declaration of Independence.
The Declaration’s final text was approved on July 4, which is why Independence Day is celebrated on that date. July 2 was nevertheless important to the people involved. John Adams even predicted that July 2 would be remembered as a great annual festival, but July 4 ultimately became the enduring public anniversary.
The two dates are often conflated because the vote and the declaration were part of the same process. July 2 recorded the political decision; July 4 approved the document that explained and announced it.