This article presents new measurements of the fragmentation properties of jets in both proton–proton (pp) and heavy-ion collisions with the ALICE experiment at the Large Hadron Collider (LHC). We report distributions of the fraction zr of transverse momentum carried by subjets of radius r within jets of radius R. Charged-particle jets are reconstructed at midrapidity using the anti-k T algorithm with jet radius R = 0.4, and subjets are reconstructed by reclustering the jet constituents using the anti-k T algorithm with radii r = 0.1 and r = 0.2. In proton–proton collisions, we measure both the inclusive and leading subjet distributions. We compare these measurements to perturbative calculations at next-to-leading logarithmic accuracy, which suggest a large impact of threshold resummation and hadronization effects on the zr distribution. In heavy-ion collisions, we measure the leading subjet distributions, which allow access to a region of harder jet frag- mentation than has been probed by previous measurements of jet quenching via hadron fragmentation distributions. The zr distributions enable extraction of the parton-to-subjet fragmentation function and allow for tests of the universality of jet fragmentation functions in the quark–gluon plasma (QGP). We find no significant modification of zr distributions in Pb–Pb compared to pp collisions. However, the distributions are also consistent with a hardening trend for zr < 0.95, as predicted by several jet quenching models. As zr → 1 our results indicate that any such hardening effects cease, exposing qualitatively new possibilities to disentangle competing jet quenching mechanisms. By comparing our results to theoretical calculations based on an independent extraction of the parton-to-jet fragmentation function, we find consistency with the universality of jet fragmentation and no indication of factorization breaking in the QGP. [Figure not available: see fulltext.].