As the relationship between the built environment and the sense of human experience becomes increasingly important, emotional geography has begun to focus on sentiments in space and time and improving the quality of urban construction from the perspective of public emotion and mental health. While youth is a powerful force in urban construction, there are no studies on the relationship between urban youth sentiments and the built environment. With the development of the Internet, social media has provided a large source of data for the metrics of youth sentiment. Based on data from more than 10,000 geolocated Sina Weibo comments posted over one week (from 19 to 25 July 2021) in Shanghai and using a machine learning algorithm for attention mechanism, this study calculates the sentiment label and sentiment intensity of each comment. Ten elements in five aspects were selected to assess the built environment at different scales and also to explore the correlations between built environment elements and sentiment intensity at different scales. The study finds that the overall sentiment of Shanghai youth tends to be negative. Sentiment intensity is significantly associated with most built environment elements at smaller scales. Urban youth have a higher proportion of both happy and sad sentiments, within which sad sentiments are more closely related to the built environment and are significantly related to all built environment elements. This study uses a deep learning algorithm to improve the accuracy of sentiment classification and confirms that the built environment has a great impact on sentiment. This research can help cities develop built environment optimization measures and policies to create positive emotional environments and enhance the well-being of urban youth.