Answer:
Non-metal elements (such as oxygen, nitrogen, fluorine, chlorine etc, *except noble gas) gain electrons more easily compared to metals and semi-metals.
All groups from Group IV to Group VIII gain electrons, specifically, group VII (7) gain electrons most easily. This group is called halogens, which includes fluorine, chlorine, bromine etc.
Atoms of elements tend to become octet by having 8 outermost shell electrons, (or 2 if there's only 1 electron shell- which is called duplet), because thats where they are the most stable. Since non-metals can become octet/duplet easier by gaining fewer electrons rather than losing more of the already existing electrons, they have a higher tendency to gain electrons.
In halogens, they already have 7 outermost shell electrons, so they only need 1 more to have 8, so they gain electrons more easily. They would not lose 7 electrons.
Same for oxygen, for example. The atoms have 6 outermost shell electrons already, so they only need to gain 2 to become octet.