In the process of rapid urbanization and accelerated transformation of urban community public space structures, the optimization of community space structure and the quality of the living environment has attracted the attention of academic circles. Existing research has shown that the well-being of community residents is positively correlated with community social capital. The starting point of this study was howaimed to increase residents’ social capital and enhance their sense of life happiness through a good community space environment design. This paper focuses on the analysis of the spatial perception level of community residents and the correlation between environmental space design elements and social capital and explores the environmental factors that affect the accumulation of social capital of community residents to put forward suggestions for the optimal design of community public spaces. A field survey of 30 communities in Shanghai City was conducted based on relevant theories and practical cases both at home and abroad. The six dimensions of “social cohesion”, “sense of community belonging”, “social participation”, “social network”, “social interaction”, and “neighborhood relationship” are used to assign social capital, and the six dimensions are respectively regressed with residents’ environmental perception of the community and the objective environment of the community. The correlation between the social capital of community residents and the three elements of public space (space, facilities, and social elements) was obtained. According to the public space optimization design strategy of the three elements, public space design principles for improving community social capital are proposed, including the principles of diversification, humanization, suitability, and inclusiveness, and the corresponding suggestions are proposed from three aspects: point space, line space, and surface space.