` elements whose `class` attribute value begins with `"test"`.
```css
div[class^="test"] {
background: #ffff00;
}
```
#### HTML Structure:
```html
This div will have a yellow background.
This div will also have a yellow background.
Not matched (wrong element type).
Not matched (does not start with "test").
```
---
### Example 2: Target Any Element with Class Starting with "test"
This example targets *any* HTML element (not just ``s) whose `class` attribute value begins with `"test"`.
```css
[class^="test"] {
background: #ffff00;
}
```
#### HTML Structure:
```html
Matched div element
Matched paragraph element
``` --- ### Example 3: Practical Use Case (Styling Secure Links) A common real-world application is styling external or secure links differently by checking the `href` attribute. ```css /* Add a lock icon next to secure HTTPS links */ a[href^="https://"] { background: url('lock-icon.png') no-repeat left center; padding-left: 20px; } ``` --- ## Browser Support The `[attribute^=value]` selector is highly compatible and supported by all modern web browsers. | Browser | Supported Version | | :--- | :--- | | **Google Chrome** | Yes | | **Mozilla Firefox** | Yes | | **Safari** | Yes | | **Opera** | Yes | | **Internet Explorer** | IE8+ | > **Note for Internet Explorer 8:** To ensure the `[attribute^=value]` selector works correctly in IE8, you must declare a valid `` at the very beginning of your HTML document.
YouTip