Yogesh Chauhan's Blog

CSS Attribute Selectors

in CSS on September 24, 2020

We can style HTML elements that have specific attributes or attribute values.

We can put the attribute value in single-quotes or double-quotes. It will work without quotes, but it’s not valid as per the CSS standard.

Selector Remarks
[attribute] Element with attribute
[attribute='value']  Where attribute has value attr_value
[attribute~='value'] Where value containing a specified word.
[attribute^='value'] Where attribute’s value begins with attr_value
[attribute$='value'] Where attribute’s value ends with attr_value
[attribute*='value'] Where attribute contains any_value anywhere
[attribute|='value'] Used to select elements with the specified attribute
starting with the specified value.
[attribute='value' i] Where attribute has value value, ignoring
attr_value’s letter casing. 



[attribute = "value"]

[attribute *= "value"]

[attribute ~= "value"]

[attribute ^= "value"]

[attribute $= "value"]

[attribute |= "value"]

[attribute="value" i]

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
OOP, Class and Objects Strategies For Beginners (PHP)PHPUNION and UNION ALL in PostgresPostgresOptional arguments, Default parameters and REST parameters in JavaScriptJavaScriptCreate a responsive image gallery using CSS gridCSSRendering Elements in ReactReactHow to add recaptcha version 3 to PHP website?PHPHow to create a Horizontal Scroll on button click using JavaScript?JavaScriptHow to Make a Simple Module with a Form and Menu Link in Drupal 7.x?DrupalHow to compress images with gulp in WordPress?WordPressThe Sort and Compare Functions in JavaScriptJavaScriptList of social media icon logo color codes in HEXMiscellaneousHow to hide a DIV on clicks outside of it using jQuery?jQuery