About 400 million years ago, during the Devonian period, the Earth was going through an especially warm period, and some of the smaller oceans and lakes were drying up, leaving big muddy puddles all around them. This was no good for fish, which had less room to swim around in, and sometimes got stranded in the mud.
Some of the fish got bigger and meaner, so they could attack and eat other fish. But other fish evolved to take advantage of the new muddy puddles, and live in the mud, where the mean fish couldn't get them.
The biggest problems about living in mud puddles were getting stuck in the mud and not finding enough water to get enough oxygen to breathe. Lungfish gradually evolved to solve both problems. They began to use their swim bladders to breathe with, and they doubled the bones in their fins so they could push off with their fins to move in the mud.
It turned out to be a great idea to go live on land, where there was plenty of room and hardly anything to eat you, and even plenty of grasshoppers and ferns to eat for food. Some lungfish began to spend more and more time on land. By about 375 million years ago, some of these lungfish evolved into frogs.