Place the onion and garlic in a large non-reactive bowl. Add the sugar, salt, and peppercorns to a small sauce pot. Add the vinegar and stir until the sugar is dissolved. Place a lid on the pot and bring the mixture up to a boil over medium-high heat.
Once boiling, pour over the sliced onions. Make sure all the onions are submerged, and let the mixture cool to room temperature.
Once cool, you can use the onions immediately or store in the refrigerator.