Background Sleep health has recently been incorporated into the Life's Essential 8 of the American Heart Association. Little is known about the associations between changes in nighttime sleep behavior and healthy outcomes, especially for the elderly. This study explores associations between transition of nighttime sleep duration and sleep quality and cardiovascular diseases (CVD) among middle-aged and older adults in China. Methods Data were derived from the China Health and Retirement Longitudinal Study from 2011 to 2018, and a total of 7,905 participants age >= 45 years were included. Participants were classified according to nighttime sleep duration (6-8, < 6 or > 8 h) and sleep quality assessed by the number of restless sleep days in the past week (< 3, 3-7 days). Four groups of the changing patterns in nighttime sleep duration and sleep quality between 2011 and 2015 were identified. CVD including heart disease and stroke was defined based on medical diagnosis. Robust Poisson regression and the restricted cubic spline were employed to evaluate the association between the transition of nighttime sleep behavior and the risk of CVD. Results Compared to participants with consistently optimal nighttime sleep duration, those with consistently non-optimal (incidence rate ratio [IRR]: 1.36, 95% confidence interval [CI]: 1.15-1.61, P < 0.001), optimal to non-optimal (IRR: 1.20, 95% CI: 1.02-1.43, P = 0.032), or non-optimal to optimal (IRR: 1.23, 95% CI: 1.02-1.48, P = 0.026) transition in nighttime sleep duration had higher risks of CVD. Additionally, those with a good to poor (IRR: 1.42, 95% CI: 1.20-1.68, P < 0.001) or a consistently poor (IRR: 1.55, 95% CI: 1.32-1.83, P < 0.001) changing pattern in nighttime sleep quality were associated with an increased risk of CVD compared to those with a consistently good changing pattern. There was a U-shaped association between changes in nighttime sleep duration and the incidence of CVD in sleep-deprived people. Changes in sleep quality and the risk of CVD exhibited a linear association. Conclusions Persistent non-optimal nighttime sleep duration and poor sleep quality are associated with an increased risk of CVD in middle-aged and older adults. These findings highlight the importance of considering transitions in sleep behavior in CVD risk assessment for middle-aged and older adults, and emphasize the significance of long-term exposure to poor sleep behavior on their cardiovascular health.