Sep 2, 2024
This isn't a good comparison for multiple reasons. CSS selectors are matched from right to left, so if you have a moderately large HTML document with div, span, h1, p, etc., and you use a selector like body .section .content p {}, all p elements are matched first, then .content, and so on. In a typical project with thousands of selectors, this can add up to something significant in the end. Therefore, avoid nesting the CSS / HTML DOM structure unnecessarily. Keep everything as simple as possible.