CSS [attribute^=value] Selector (original) (raw)

Last Updated : 29 Aug, 2024

The [attribute^=value] selector selects elements whose attribute value begins with a given attribute.

**Syntax:

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

**Example: In this example, The CSS selector p[class^="for"] targets

elements with a class attribute that starts with "for" and applies a green background color and white text color.

html `

CSS [attribute^="value"] Selector
<!-- CSS property -->
<style>
    p[class^="for"] {
        background: green;
        color: white;
    }
</style>

[attribute^=value] Selector

<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>

`

**Output:

CSS attribute Selector example output gfg

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