codegurukool.com · Free coding tutorials & online compiler

Home › CSS Tutorial › Attribute selectors

Attribute selectors

Select by attribute.

[type], [type='text'], [href^='https'] (starts with), [href$='.pdf'] (ends with), [class*='btn'] (contains).

Example code

<style>
input[type='text']{background:#ffd}a[href^='https']{color:green}a[href$='.pdf']{color:red}
</style>
<input type='text'><input type='number'><br><a href='https://x.com'>https</a> <a href='a.pdf'>pdf</a>

Run this code in the online editor

← CSS dropdownsCSS forms →