Glossary

CSS Selector

Definition

A CSS selector is a pattern or rule that lets you choose which HTML elements you want to style.

In CSS, a rule looks like this:

selector {
 property: value;
}

The selector part determines which elements the property: value styling should apply to.
In web scraping and automation, selectors serve a similar role - they define which elements to locate, extract, or interact with.

Why Are CSS Selectors Important?

  • They let you target elements precisely, not just by tag name (like <div>), but also by class, ID, attribute, position, or state (hovered, checked, etc.).
  • Good selectors make your CSS clean and efficient - fewer rules, less redundancy.
  • Poor selectors (too broad or overly complex) can slow down rendering or cause unintended styling.
  • In web scraping, precise selectors are critical for locating the right data or clickable element.
    A robust selector ensures you can consistently extract text, follow links, or trigger actions - even if the page layout changes slightly.

Types of CSS Selectors - Simple to Sophisticated

Here are some common types of selectors:

Selector Type What It Targets Example What It Selects
Type (element) All elements of a certain tag p All <p> elements
Class Elements with a given class .highlight <div class="highlight">…
ID A specific element with an id #main-header <h1 id="main-header">…
Attribute Elements with certain attributes input[type="text"] All <input> elements whose type="text"
Pseudo-classes Elements in a certain state a:hover A link when the user hovers over it
Pseudo-elements Parts of elements p::first-line The first line of a <p> text
Combinators Relationships between elements ul > li <li> elements directly inside a <ul>
Descendant Elements nested anywhere within another div p All <p> elements inside any <div>

CSS has many more, including advanced selectors like :nth-child(), :not(), :has(), etc.

Example

<div class="card">
 <h2>Title</h2>
 <p class="intro">Some introduction text.</p>
 <a href="#">Read more</a>
</div>

Some example selectors:

  • .card h2 → the <h2> inside an element with class card
  • p.intro → the <p> that has class intro
  • .card > a → the <a> that is a direct child of .card (not nested deeper)
  • a:hover → style the link when hovered over
In Short: A CSS selector is a pattern that identifies which HTML elements should receive certain styles. In web scraping or browser automation, the same selectors help locate, read, and interact with specific parts of a webpage. They range from simple (tag name, class, ID) to complex (nested relationships, states, attribute conditions), giving you powerful control over both styling and structured content extraction..

Hi, we’re Kameleo!

Trusted by thousands of growth hackers, and enterprises worldwide, Kameleo makes browser automation and web scraping smarter, safer, and unstoppable. With our anti-detect browser, you can bypass anti-bot defenses, and stay one step ahead - all with human-like browsers.