Practical guides

CSS selector guide

ID, class, data attribute and good/bad examples for stable selectors in visual editors.

Last updated: May 22, 20268-14 minBeginner to intermediate
Start free See pricingMethodology

What is a CSS selector?

A CSS selector is an address for finding the right HTML element on a page. In the Testvoy visual editor, it tells which button, heading or banner should change.

Should be unique

Should select the same element on mobile

Should not break easily when layout changes

Stable selector example
<button data-testvoy="hero-primary-cta">
  Start free
</button>

/* Good */
[data-testvoy="hero-primary-cta"]

/* Fragile */
body > div:nth-child(3) > section:nth-child(2) > button

Selector examples

ID selectors are strong when the id is unique. Class selectors can be risky when reused. Data attribute selectors are usually the most stable for experiments.

#signup-button

.cta-button

[data-testid="pricing-cta"]

button.primary-cta

.hero .cta-button

a[href*="/pricing"]

Selectors to avoid

body > div:nth-child(3) > section:nth-child(2) > button

  • Unique?
  • Works on mobile?
  • Appears after SPA route changes?
  • Preview selects the right element?

Frequently asked questions

Who is CSS selector guide for?

Marketing, growth, product and developer teams can use the same guide at different depths.

Do I need a developer?

Not for basic visual changes and report reading; SDK, custom events, custom JS or enterprise security benefit from technical support.

How do I know it worked?

Verifier, recent events, preview, QA checklist and report warnings show setup and experiment health.

What is the common mistake?

Wrong project keys, missing goals, fragile selectors, early decisions on small samples and skipped mobile QA are common.

Docs

Try this guide in the app

Finish setup, create your first experiment and read the report with cleaner data in Testvoy.