Differential production cross sections of J/$\psi$ and $\psi$(2S) charmonium and $\Upsilon$(nS) (n = 1, 2, 3) bottomonium states are measured in proton-proton collisions at $\sqrt{s} =$ 13 TeV, with data collected by the CMS detector at the LHC, corresponding to an integrated luminosity of 2.3 fb$^{-1}$ for the J/$\psi$ 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 $\psi$(2S) to J/$\psi$, $\Upsilon$(2S) to $\Upsilon$(1S), and $\Upsilon$(3S) to $\Upsilon$(1S) production.
The production of $\Upsilon$(2S) and $\Upsilon$(3S) mesons in lead-lead (PbPb) and proton-proton (pp) collisions is studied in their dimuon decay channel using the CMS detector at the LHC. The $\Upsilon$(3S) meson is observed for the first time in PbPb collisions, with a significance above five standard deviations. The ratios of yields measured in PbPb and pp collisions are reported for both the $\Upsilon$(2S) and $\Upsilon$(3S) mesons, as functions of transverse momentum and PbPb collision centrality. These ratios, when appropriately scaled, are significantly less than unity, indicating a suppression of $\Upsilon$ yields in PbPb collisions. This suppression increases from peripheral to central PbPb collisions. Furthermore, the suppression is stronger for $\Upsilon$(3S) mesons compared to $\Upsilon$(2S) mesons, extending the pattern of sequential suppression of quarkonium states in nuclear collisions previously seen for the $\psi$/J, $\psi$(2S), $\Upsilon$(1S), and $\Upsilon$(2S) mesons.