The DNA fragments, contained in the gel matrix, are all huddled toward one area in a pile. Once they are all together, an electrical pulse is applied to the gel matrix. DNA fragments have a negative charge, so this pulls them all toward the positive end of the electric pulse.
The trick to this is that all DNA fragments will travel at the same speed relative to their size, and smaller fragments travel faster. This has the effect of separating all of the fragments according to size.