The origin of Uranus and Neptune is still unknown. In particular, it has been challenging for planet formation models to form the planets in their current radial distances within the expected lifetime of the solar nebula. In this paper, we simulate the in situ formation of Uranus and Neptune via pebble accretion and show that both planets can form within ∼3 Myr at their current locations, and have final compositions that are consistent with the heavy element to H-He ratios predicted by structure models. We find that Uranus and Neptune could have been formed at their current locations. In several cases a few earth masses (M ⊕ ) of heavy elements are missing, suggesting that Uranus and/or Neptune may have accreted ∼1-3 M⊕ of heavy elements after their formation via planetesimal accretion and/or giant impacts.