Organismal development and many cell biological processes are organized in a modular fashion, where regulatory molecules form groups with many interactions within a group and few interactions between groups. Thus, the activity of elements within a module depends little on elements outside of it. Modularity facilitates the production of heritable variation and of evolutionary innovations. There is no consensus on how modularity might evolve, especially for modules in development. We show that modularity can increase in gene regulatory networks as a byproduct of specialization in gene activity. Such specialization occurs after gene regulatory networks are selected to produce new gene activity patterns that appear in a specific body structure or under a specific environmental condition. Modules that arise after specialization in gene activity comprise genes that show concerted changes in gene activities. This and other observations suggest that modularity evolves because it decreases interference between different groups of genes. Our work can explain the appearance and maintenance of modularity through a mechanism that is not contingent on environmental change. We also show how modularity can facilitate co-option, the utilization of existing gene activity to build new gene activity patterns, a frequent feature of evolutionary innovations.