CSS | [attribute^=value] Selector

The [attribute^=value] selector is used to select those elements whose attribute value begins with given attribute.

Syntax:

[attribute^=value] {
    // CSS Property
}

Example:



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
CSS attribute Selector example output gfg

Supported Browsers: The browser supported by [attribute^=value] selector are listed below:

  • Google Chrome 4.0
  • Internet Explorer 7.0
  • Firefox 3.5
  • Safari 3.2
  • Opera 9.6


My Personal Notes arrow_drop_up

Computer Engineering student at St Francis Institute of Technology with good programming and problem-solving skills Passionate about solving real world problems through technology and implementing innovative ideas Looking to secure a responsible career opportunity to utilize my training and skills,

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.