Quarks do indeed have electric charge, but they do not primarily bind together through the electromagnetic force. Instead, they are primarily bound by the strong nuclear force, also known as the strong interaction.
The strong nuclear force is one of the fundamental forces in nature, responsible for holding the atomic nucleus together. It is much stronger than the electromagnetic force at small distances. The strong force is carried by particles called gluons, which interact with quarks and mediate the strong interaction.
The reason quarks do not bind together through the electromagnetic force is due to a property called "color charge." Quarks carry a different type of charge known as color charge, which is a property associated with the strong force. Color charge is a property that arises from the mathematical framework of quantum chromodynamics (QCD), which describes the strong interaction.
In contrast to electric charge, which can be positive or negative, color charge comes in three "colors" referred to as red, green, and blue (although these colors do not correspond to the colors we perceive with our eyes). The interaction of quarks and gluons through the exchange of color charge allows for the strong force to bind quarks together and form composite particles, such as protons and neutrons.
The electromagnetic force, mediated by photons, does play a role in the interactions of charged particles, including the interactions between protons and electrons within atoms. However, when it comes to the strong interaction and the binding of quarks within particles, it is the strong nuclear force and the exchange of gluons that dominate.