"We all know that our freedoms are dependent on an incredible group of men and women in uniform and their families who look out for us every single day," Obama said on Monday.
"For those in our military who could not attend, we just want to say how much we admire, respect and appreciate everything you do to fight for our freedom every single day." The story of American independence is "something that we have to fight for every single day," he added.
"It involves us respecting each other. And it involves us recognizing that there are still people in this country who are going hungry -- and they're not free because of that."
"There are still people in this country who can't find work -- and freedom without the ability to contribute to society and put a roof over your head or look after your family, that's not yet what we aim for."
He spoke inside the White House after a concert originally scheduled to be held outside was moved because of bad weather. Rapper Kendrick Lamar and singer Janelle Monae headlined the event.
Obama ended by saying his daughter Malia's 18th birthday also fell on July 4. "And just because it's a job of a father to embarrass his daughters, I've got one last job," he said before leading the singing of "Happy Birthday."
The capital's annual fireworks show took place afterward, marred by rain clouds.