Differential production cross sections of prompt J/ψ and ψ(2S) charmonium and ϒ(nS) (n=1,2,3) bottomonium states are measured in proton–proton collisions at s=13TeV, with data collected by the CMS detector at the LHC, corresponding to an integrated luminosity of 2.3 fb−1 for the J/ψ and 2.7 fb−1 for the other mesons. The five quarkonium states are reconstructed in the dimuon decay channel, for dimuon rapidity |y|<1.2. The double-differential cross sections for each state are measured as a function of y and transverse momentum, and compared to theoretical expectations. In addition, ratios are presented of cross sections for prompt ψ(2S) to J/ψ ϒ(2S) to ϒ(1S), and ϒ(3S) to ϒ(1S) production.