To evaluate a method for measuring breast density using photon-counting spectral mammography. Breast density is an indicator of breast cancer risk and diagnostic accuracy in mammography, and can be used as input to personalized screening, treatment monitoring and dose estimation. The measurement method employs the spectral difference in x-ray attenuation between adipose and fibro-glandular tissue, and does not rely on any a priori information. The method was evaluated using phantom measurements on tissue-equivalent material (slabs and breast-shaped phantoms) and using clinical data from a screening population (n=1329). A state-of-the-art nonspectral method for breast-density assessment was used for benchmarking. The precision of the spectral method was estimated to be 1.5-1.8 percentage points (pp) breast density. Expected correlations were observed in the screening population for thickness versus breast density, dense volume, breast volume, and compression height. Densities ranged between 4.5% and 99.6%, and exhibited a skewed distribution with a mode of 12.5%, a median of 18.3%, and a mean of 23.7%. The precision of the nonspectral method was estimated to be 2.7-2.8 pp. The major uncertainty of the nonspectral method originated from the thickness estimate, and in particular thin/dense breasts posed problems compared to the spectral method. The spectral method yielded reasonable results in a screening population with a precision approximately two times that of the nonspectral method, which may improve or enable applications of breast-density measurement on an individual basis such as treatment monitoring and personalized screening.