Browser developers optimize the most common cases. Since classes are used very often to fit styles, they should implement this as efficiently as possible. When they load in CSS, they index classes to make this possible.
Since random selectors, such as title="home" , are not used very often, they can get away from the implementation using simpler searches. This will not have a big impact on performance, because it will rarely be used.
Classes also require special handling in the browser, since an element can have several classes, for example. class="foo bar baz" . When parsing a document, the browser must break it so that it can match any of them with CSS selectors.
source share