Specificity of attribute selectors
August 23, 2020

Attribute selectors have specificity same as class selector and pseudo class.


Here is W3's guide on Calculating a selector’s specificity: w3.org

Quoting W3 guide here,

A selector’s specificity is calculated for a given element as follows:

count the number of ID selectors in the selector (= A)
count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= B)
count the number of type selectors and pseudo-elements in the selector (= C)
ignore the universal selector


*[type=radio] // 0-1-0

.class_name input[type="text"] { }  // 0-2-1

Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 5 How to create flickering text using CSS? Mar 4 How to use data-* Attributes in HTML? Mar 4 The substr() method in JavaScript and how it’s different from substring() Mar 4 A complete guide to add responsive YouTube videos using HTML and CSS Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress?

You might also like these

Some EASY-to-Understand CSS media query examplesCSSSQL Inner JoinSQL/MySQLWordPress: How to display slider repeater fields in ACF?WordPressHow to get ACF values from custom post type?WordPressArray destructuring and Object destructuring in JavaScriptJavaScriptHow to check if the page is single post page in WordPress?WordPressA Quick Comparison of JOIN and Subquery in SQLSQL/MySQLObject destructuring in JavaScript: Unpacking fields from objects passed as function parameterJavaScriptJavaScript String Properties and MethodsJavaScriptFull and Partial ROLLUP in Postgresql with ExamplesPostgresWordPress: How to get ACF field values from another post?WordPressWHERE Clause in PostgresPostgres