Open In App
Related Articles

CSS [attribute*=value] Selector

Improve Article
Improve
Save Article
Save
Like Article
Like

The [attribute*=”str”] selector is used to select those elements whose attribute value contains the specified substring str. This sub-string could be at the start, end, or in middle of the class.

Syntax:

element [attribute*="str"] {
    // CSS Property
} 

Example: In this example, the selected <p> elements with the class containing “for” will have a green background and white text color, as defined by the corresponding CSS rules.

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        CSS [attribute*="str"] Selector
    </title>
 
    <!-- CSS property -->
    <style>
        p[class*="for"] {
            background: green;
            color: white;
        }
    </style>
</head>
 
<body>
    <h1>GeeksForGeeks</h1>
    <h2>[attribute*=value] Selector</h2>
 
    <p class="GeeksforGeeks">GeeksforGeeks</p>
    <p class="forGeeks">A computer science portal</p>
    <p class="Geeks">Sudo GATE</p>
    <p class="for">Sudo placement</p>
</body>
 
</html>


Output:

Supported Browsers: The browser supported by [attribute*=value] Selector is listed below:

  • Google Chrome 4.0
  • Internet Explorer 7.0
  • Firefox 3.5
  • Apple Safari 3.2
  • Opera 9.6
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 04 Jul, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials