When "quarks" were invented by Gell-Mann and Zweig, they were simply associated the charges (2/3 elementary charges for the up, -1/3 for the down quark) such that the correct charge pattern for the hadrons resulted. See,
Nowadays this charge pattern, together with the 3 colors of the color SU(3) underlying QCD, make the Standard Model consistent in avoiding a chiral anomaly of the weak gauge group ##\mathrm{SU}(2)_{\text{wiso}} \times \mathrm{U}(1)_{\text{Y}}.##