The Continental Congress voted to approve the a motion for independence in a secret meeting on July 2nd. Over the next two days the worked and revised the text while Thomas Jefferson worked through the night writing the Declaration of independence. On the morning of July 4th at a little after 11 am the Congress voted and adopted on July 4th. Word of the declaration began to spread through Philadelphia and on July 8th printed copies began to circulate in Philadelphia.
The new government of the United States didn't recognize July 4th until 1781, and it was first known as independence day in 1791. In 1804 the Federal Government recognized July 4th as an unpaid federal holiday.