What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

CSS selectors choose which elements a rule can match; specificity helps decide between declarations that remain in competition after earlier cascade rules are applied. To keep styles easy to maintain, use selectors that match a stable component or semantic hook, and avoid adding selector weight just to force an override.

How do CSS selectors work?

A selector identifies the elements to which a CSS rule’s declarations may apply. Different selector forms describe an element’s type, attributes, classes, state, or relationship to other elements.

Selector What it matches
button Every button element (type selector).
.notice Elements with the notice class.
#main The element with the main ID.
[type="email"] Elements whose type attribute equals email.
nav > a Anchor elements that are direct children of a nav element.
nav a Anchor elements anywhere inside a nav element.
a:hover Anchor elements in the hover state.
h1, h2, h3 Elements matching any of the three selectors in the comma-separated selector list.

The space in nav a is a descendant combinator; > in nav > a means direct-child relationship. Combinators describe which elements are related, but do not add specificity weight. A selector list groups alternatives, so one rule can apply to elements matching any listed selector. See MDN’s selector-list documentation.

What is CSS specificity?

Specificity is one part of the cascade: it is a weight browsers use to decide between competing declarations that have made it through earlier cascade criteria. MDN Web Docs puts it this way: “The specificity algorithm calculates this weight based on the number of selectors of each weight category in the selector matching the element (or pseudo-element).”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

For ordinary selectors, think of specificity as three columns, compared from left to right—not as a decimal number:

  • ID column: ID selectors such as #main.
  • Class-like column: class selectors such as .notice, attribute selectors such as [type="email"], and pseudo-classes such as :hover.
  • Type-like column: type selectors such as button and pseudo-elements such as ::before.

For example, #main .notice button has specificity 1-1-1: one ID, one class-like selector, and one type selector. A competing .notice #main button has the same counts, so neither selector wins on specificity alone. The universal selector (*) and combinators add no weight.

How pseudo-classes affect specificity

:where() and everything inside its parentheses contribute zero specificity. This lets you express detailed matching logic without making a rule harder to override on specificity alone. By contrast, :is(), :not(), and :has() take their weight from their arguments: the most specific argument governs. The pseudo-class name itself does not add a separate class-like point.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

For example, :where(.article, .notice) a has specificity 0-0-1, from the a type selector. :is(.article, .notice) a has specificity 0-1-1, because its most specific argument is a class selector. The selectors can describe similar matches, but they do not carry the same override weight. MDN explains the details for :where() and :is().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where specificity sits in the cascade

Specificity does not decide every CSS conflict. The browser first considers which declarations apply, then resolves cascade precedence such as origin, importance, and layer. Specificity is compared among declarations that remain in the same winning precedence bucket. If specificity ties, scope proximity can matter where scoped styles are involved; if that also ties, source order decides. MDN’s introduction to the CSS cascade describes the complete order.

This is why a more specific selector does not automatically win: a declaration from a higher-precedence origin, importance level, or layer can beat it before specificity is considered. Inheritance is a separate distinction: a declaration directly targeting an element takes precedence over an inherited value for that property.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Use layers to organize precedence

For a larger stylesheet, @layer can group styles by purpose—for example, reset, vendor, base, components, and overrides. Layer precedence can settle conflicts between groups without building increasingly specific selectors. But normal unlayered author declarations outrank normal layered author declarations, so make the layer arrangement explicit rather than assuming that a later-looking rule always wins. See MDN’s cascade layers guide.

How do I make a CSS selector less specific?

Start with the styling hook, not with selector length. A selector should match the intended elements accurately, remain meaningful when unrelated markup changes, and carry only as much specificity as the stylesheet needs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prefer stable component hooks to incidental paths

If a title belongs to a card component, a class such as .card__title usually expresses that intent more clearly than main article section div h2. The long chain depends on a particular nesting structure; a harmless wrapper or rearranged layout may break the match. A short selector is not automatically correct, though: check that its class or semantic hook does not also select elements you did not intend to style.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Choose between :where() and :is() deliberately

Use :where() when a detailed scope is useful for matching but should not raise specificity. Choose :is() when its argument-based specificity is appropriate for the rule. Treat :not() and :has() as matching tools too, rather than as concealed ways to manipulate specificity.

Keep nesting from obscuring weight

CSS nesting can make a selector look shorter in source while its effective specificity still reflects the nested selector structure. When a nested rule is unexpectedly hard to override, inspect the resulting selector and its specificity rather than judging by indentation or visual length. MDN covers this in CSS nesting and specificity.

Compare candidate selectors by maintainability

Approach Match accuracy Specificity weight Markup resilience Cascade fit
main article section div h2 May target a narrow position, but depends on the full structure. Four type selectors; modest weight, despite the long chain. Low if wrappers or nesting change. May be a poor fit if the rule is meant to style a reusable component.
.card__title Targets elements deliberately marked as card titles. One class-like selector. Usually resilient to unrelated structural changes as long as the hook remains. Suitable for a component rule when the class is owned and maintained with that component.
:where(.article, .notice) a Targets links inside either named region. One type selector; the :where() contents add zero. Independent of deeper nesting, but depends on the region classes. Useful when the detailed scope should remain easy to override.
:is(.article, .notice) a Targets links inside either named region. One class-like selector plus one type selector. Independent of deeper nesting, but depends on the region classes. Use when the argument-derived weight is wanted or acceptable.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why is my CSS rule being overridden?

A rule may lose because it does not match the element, because another declaration wins an earlier cascade criterion, because a competing selector has greater specificity, or because a later rule wins a tie. An inherited value can also make the computed result look unexpected when no declaration directly targets the element.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
  1. Verify the match. Check that the selector actually selects the intended element and that the relevant state or attribute is present.
  2. Inspect competing declarations. In browser developer tools, select the element and review its matched rules and computed property to see which declarations are active, overridden, or inherited.
  3. Walk precedence in order. Compare origin and importance first, then layer precedence, then specificity. Do not jump straight to adding an ID or !important.
  4. Check tie-breakers. If specificity is equal, consider scope proximity when @scope is involved, then source order.
  5. Separate inheritance from direct targeting. Find whether the value comes from a rule on the element itself or from an ancestor.
  6. Fix the underlying conflict. Remove an accidental competing declaration, use a stable selector, clarify layer organization, or—only for a deliberate constraint—use a limited, documented important declaration.

When should you use !important?

!important changes cascade precedence; it is not simply a specificity boost. It can be appropriate when a declaration must honor a deliberate constraint, but using it to compensate for unclear layer or selector organization makes later maintenance harder. First identify why the current declaration loses; use an important declaration only when its stronger precedence is intentional and documented. MDN details its relationship to cascade and specificity.

Further reading

For a broad reference rather than a selectors-only manual, O’Reilly lists CSS: The Definitive Guide, 5th Edition, by Eric Meyer and Estelle Weyl. The publisher’s contents page includes selectors, specificity, the cascade, and cascade layers. O’Reilly says the fifth edition reflects CSS as of the end of 2022, so consult current documentation for details that may have changed.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.