In general, ioniation energy increases from left to right across a given period. Th electrons are added to same principal shell. The nuclear charge increases and due to poor shielding, the effective nuclear charge increases. Due to this, the atomic radii decrease and the ionization energy increases.
Aluminum, however, has a lower ionization energy than magnesium. The electronic configuration of Mg is [Ne]3s2. The electronic configuration of Al is [Ne]3s23p1. Less energy is required to remove a p electron than a s electron in the same principal energy level.