Case Insensitive CSS Attribute Selector

CSS selectors never cease to amaze me in how powerful they can be in matching complex patterns. Most of that flexibility is in parent/child/sibling relationships, very seldomly in value matching. Consider my surprise when I learned that CSS allows matching attribute values regardless off case! Adding a {space}i to the attribute selector brackets will make […]

The post Case Insensitive CSS Attribute Selector appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh

CSS selectors never cease to amaze me in how powerful they can be in matching complex patterns. Most of that flexibility is in parent/child/sibling relationships, very seldomly in value matching. Consider my surprise when I learned that CSS allows matching attribute values regardless off case!

Adding a {space}i to the attribute selector brackets will make the attribute value search case insensitive:

/* case sensitive, only matches "example" */
[class=example] {
  background: pink;
}

/* case insensitive, matches "example", "eXampLe", etc. */
[class=example i] {
  background: lightblue;
}

The use cases for this i flag are likely very limited, especially if this flag is knew knowledge for you and you’re used to a standard lower-case standard. A loose CSS classname standard will have and would continue to lead to problems, so use this case insensitivity flag sparingly!

The post Case Insensitive CSS Attribute Selector appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2024-06-19T11:31:27+00:00) Case Insensitive CSS Attribute Selector. Retrieved from https://www.scien.cx/2024/06/19/case-insensitive-css-attribute-selector/

MLA
" » Case Insensitive CSS Attribute Selector." David Walsh | Sciencx - Wednesday June 19, 2024, https://www.scien.cx/2024/06/19/case-insensitive-css-attribute-selector/
HARVARD
David Walsh | Sciencx Wednesday June 19, 2024 » Case Insensitive CSS Attribute Selector., viewed ,<https://www.scien.cx/2024/06/19/case-insensitive-css-attribute-selector/>
VANCOUVER
David Walsh | Sciencx - » Case Insensitive CSS Attribute Selector. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/19/case-insensitive-css-attribute-selector/
CHICAGO
" » Case Insensitive CSS Attribute Selector." David Walsh | Sciencx - Accessed . https://www.scien.cx/2024/06/19/case-insensitive-css-attribute-selector/
IEEE
" » Case Insensitive CSS Attribute Selector." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2024/06/19/case-insensitive-css-attribute-selector/. [Accessed: ]
rf:citation
» Case Insensitive CSS Attribute Selector | David Walsh | Sciencx | https://www.scien.cx/2024/06/19/case-insensitive-css-attribute-selector/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.