🚀 We are hiring! See open positions

How to select elements by class using CSS selectors?

by Bernardas Alisauskas Dec 26, 2023 1 min read

To select elements by class value the . symbol + value can be used. For example, .product would select any element that contains product in the class attribute:

<div> <div class="product">select</div> <div class="sold product">select</div> <div class="sold product new">select</div> <div class="product-2">ignore</div> </div>

Note that this selector matches any element that contains a class value in the class list (separated by spaces). To match elements that contain the exact class value the predicate syntax can be used:

<div> <div class="product">ignore</div> <div class="sold product">select</div> <div class="sold product new">ignore</div> <div class="product-2">ignore</div> </div>
Scale Your Web Scraping
Anti-bot bypass, browser rendering, and rotating proxies — all in one API. Start with 1,000 free credits.
No credit card required 1,000 free API credits Anti-bot bypass included
Not ready? Get our newsletter instead.