True, the Continental Congress, representing the 13 colonies which originally comprised the US, declared independence in July 1776—but it wasn’t on the fourth. It was the second.
Thomas Jefferson started writing the declaration of independence in June 1776. Independence was declared on July 2. The declaration was signed on August 2, and delivered to the Brits in November.
What happened on July 4 is a matter of grammar.
After the first draft of the declaration was submitted on July 2, Congress worked on edits and tweaks—probably debating the deep meaning of its punctuation as we still are, 238 years later—until they settled on a final version on July 4.
The date was included in the draft which was then signed in August.
The conflict kept Americans from celebrating the anniversary for about a century, and only after the end of the war of 1812 did the declaration become popular again. With the date July 4 up there in fancy handwriting, it was easy to take that as the day of Independence.
And so in 1870, July 4 was made a national holiday. Independence, plus two days.
Something else worth remembering did happen on July 4: both Thomas Jefferson and John Adams, two of the founding fathers who had signed the declaration, died on that day—a few hours apart from one another, in 1826.