March 21, 2025
Ever feel like your CSS could be sharper, more efficient, and downright smarter?
Here are five underused CSS selectors that can transform how you style your web pages:
[attr~="value"]
This selector finds elements whose attribute value contains a specific word. Perfect for multi-word class names or attributes.
input[type~="email"] {
border: 2px solid #43a047;
}
Save time by avoiding complex class juggling and targeting exactly what you need.
[attr|="value"]
Great for styling elements where attributes follow a structured pattern (like language codes).
[lang|="en"] {
font-family: sans-serif;
}
Quickly style elements that share a common prefix in their attribute values.
:not()
Exclude specific elements from styling without adding extra markup.
.button:not(.disabled) {
background-color: #1e88e5;
}
Streamline your CSS by leaving out unwanted targets.
E ~ F
Select all sibling elements that follow a certain element.
h2 ~ p {
margin-top: 0;
}
Keep layouts dynamic and uncluttered without unnecessary HTML complexity.
:nth-child()
Combine :nth-child()
with other pseudo-classes for dynamic styling magic.
li:nth-child(odd):hover {
background-color: #f5f5f5;
}
Add interactivity and polished design touches with minimal code.
These five selectors are just the start. If you’re ready to level up your CSS game, grab the Teki Solves Advanced CSS Selector Cheat Sheet — packed with in-depth explanations, real-world examples, and best practices to help you write cleaner, more powerful CSS.
Download the CSS Selector Cheat Sheet Now
Keep it simple, solve the problem, and write CSS like a pro.
Author: Teki Solves