Agate forms when gas bubbles, trapped in solidifying lava, are filled with alkali and silica-bearing waters. The alkali attacks the iron in the surrounding lava, and colorful bands of iron hydroxide are created. The forming rock eventually loses water and crystallizes, leaving the bands intact.