How you can simplify your CSS with :is()
Skills:
HTML & CSS90%
Key Takeaways
Simplifies CSS using the :is() pseudo-class
Full Transcript
in this video we are exploring the is pseudo class and what is the pseudo class what does it do why does it matter how is it going to simplify your life because it definitely well it lets us write much drier css so we're going to be exploring all of that in this video stick around so this is in codepen right here if you do want to follow along you can just delete everything before general styling when you open the link in the description and you can follow along because this is all this is just general styling here we're going to start right here and we're going to be looking at the is pseudo class what is it what is it for and i'm sure in one point or another you've had selectors where you want to select say you have a header and you want to get both the h1 and the link in here to be a different color compared to maybe things you have in other places so you come in and you do something like header h1 comma header header you got to do things right like that header h1 header a and then we can say a color of let's go with lime green for something interesting and look at that they're lime green don't use that color on that background it is terrible accessibility but it is working and you've selected both of them so we have a compound selector here and with this compound selector we have a comma separating so we can do multiple selectors now if you can get really complex with these now we do want to be careful with compound selectors like this where we're spacing them out we're getting the children i do think it's fine doing this but you just want to be a little bit careful and not go overboard it pushes up specificity there can be other issues but sometimes it's very useful and you can get much drier css by chaining your selectors together like this and having comma separated ones but you can also run into issues a on some really big things it can get really bulky but if you put an invalid selector here and i don't know how this would happen but say you're going fast or something and you do that and that means nothing or whatever it is something happens and for some reason you have this big chain of selectors you have all of these different things and one of them is invalid it doesn't work in your code anymore this entire css rule here it is gone in the garbage the browser ignores the entire thing this is very different than when you have a typo here so if i said uh like color is one t 0 p and the browser doesn't know what that is this is very different right because then this one line of code will get ignored but if you have something like this it's throwing the entire rule out let's even you know for fun font family we'll go with a serif just so we can see a difference we'll say that the colors there we'll see a font size of 10 ram just so we can really see nothing is working but then when i fix that one little thing the entire thing will kick in and it works everywhere and it looks terrible um but just to show you how that is working and why you do have to be a little bit careful i don't think that's something you'll run into often but it can be really annoying when it does happen where is comes in is instead of writing things like this what you could do is you could say header and then here we could say is and inside of this we can put all the different things that we want so i could say h1 comma a and here we can see that this is working for my serif and then let's come in here with the color we won't use lime green let's use uh turquoise now turquoise you gotta spell spell things right turquo baseball turquoise turquoise ha i got it that's even worse than before okay let's go with a dark color there we go so we can see that it's working so here uh what we're doing is a header is and then h1 and comma a so the nice thing with this is you don't need to have such a big rule you can sort of space things out a little bit like this you're only putting the parent selector once when you have this um when using a compound selector like this one you only have to list this at once so like say you had other things in here you had a header say we had a button that could have end up in there and then here you'd have a header let's just say if ever there's a small tag for some reason anything like that you know this gets longer and longer and longer and when you want to make a change in here it can be a little bit annoying so here it's a little bit easier where you can do h1 then dot btn comma small and you can list them all out here so you only have to do it on one selector instead of having a whole bunch of selectors and the other thing that's nice with this you can see my text is all purple is if i muck one of these up so this button somehow it ends up being invalid and i'm using something that doesn't work or i shouldn't do on the button actually we should leave that as a class i'll do it on the a again is you'll see that the links actually uh purple's a bad color though let's go back with green because one of them was purple by default but you can see now this is green um but the green isn't working on my links down here and the reason that's happening is because this is my invalid selector so only the invalid selector is being thrown out it's not ditching the entire rule so it's much more forgiving on things like that so that is a nice benefit of the is selector like this and another way we could use the is selector in a bit more of a cool way is you don't have to use it the way i was doing it so just to reiterate a little bit here we have my card then we could say is h2 comma a so we could select my h2 and my a that are in there and say color is red and now over here you can see that and my links inside of here have all changed to red but another really cool thing you can actually do here instead of doing it that way is the other way around so what you could do is you could actually say something like we could start with our is selector so we could say is uh we could even say header space card dot card and just for fun i don't know why you would want to do this but then we could say uh h or then we in here we could say p hover and i don't know why you do it on a paragraph maybe a link would make more sense but p hover here is color of red quick example just so we can see it actually working and you can see all of these paragraphs now are working this i think is the more useful used uh use of this you know this while this is can be a little bit bulky here this is the equivalent of writing header p hover comma uh dot card p hover and then comma and you keep going like that you have to keep doing your p hover here so it's kind of cool that you can just have that one p hover out here so you list all the things you want put the one compound here and it just works just like that now there is one really important thing that you're going to have to take into account if you're doing this um and i don't think you'll run into it too often but there is a specific specificity specificity i got it a specificity thing that comes up when you are doing this and so on this if i say card and then we do our is selector our pseudo pseudo class here and we say is title comma key and we say color is red now what's really interesting here is you can see they've all changed to red and later on maybe you forgot you did that and then here you have a card p and this has a color of yellow well it actually will be staying there we go it is staying red and that's because this actually has higher specificity than this even though you would think this is my card with my p on here the is itself does not contribute to the specificity but what does is this title here so it's whatever you have here the height the thing with the highest specificity within this group is what is getting the we're just setting the specificity of all of this um so you do want to be a little bit careful with that um and just to show you that this would work uh without the is there if i just put is p here like that now the yellow is actually going to kick in because this specificity is the same or equal to this one and this one is coming second because if i move that up to the top here now they will switch to red because this is coming second so you do have to be a little bit careful with that and just know that it's the thing with the highest specificity within this that is working another thing another little thing along the way that could be important to know as well is you can do some interesting stuff so i could actually say p space a here and you can see that the paragraph uh the links inside the paragraph are changing to red so you can do complex selectors within the is here i'm not sure what the browser support is for that i know complex selectors within these pseudo classes like not and other things the support is gaining but it's not everywhere so you might want to be a little bit careful with that or just double check and do some cross browser compatibility but for overall browser support it's actually really good and as long as you don't worry too much about internet explorer these days which i hope you're not having to i know some people have to because of their work but overall i think internet explorer is something we don't have to worry about anymore and if that is the case then the is selector or the pseudo class i should say is good to go and you can definitely be using it on your projects and that is it that is the is pseudo class i really hope that you like this if you'd like to know more advanced selectors and combinators and all of that type of thing i do have a video that dives into it it should be showing up on the screen right now or it is also linked down in the description below as well thank you very much for watching i really hope you enjoyed this and i hope you can find some good use cases for it we just sort of scratched the surface here but it is something that i'll definitely be looking at using more and more in my projects going forward a huge thank you to my patrons for their support each and every month including zach who is my enabler of awesome and of course until next time don't forget to make your corn on the internet just a little bit more awesome
Original Description
The :is() pseudo-class is relatively new, but browser support is pretty good now! It's a nice way to dry up your CSS and turn some otherwise complex selectors into something much more managable!
Codepen: https://codepen.io/kevinpowell/pen/RwojMKB
Step up your game with advanced CSS selectors and combinators: https://www.youtube.com/watch?v=Bcr70LIJcOk&list=PL4-IK0AVhVjPRj8P56TtFX2hg33BlbT3x&index=2
#css
--
Come hang out with other dev's in my Discord Community
💬 https://discord.gg/nTYCvrK
---
Keep up to date with everything I'm up to
✉ https://www.kevinpowell.co/newsletter
---
Help support my channel
👨🎓 Get a course: https://www.kevinpowell.co/courses
👕 Buy a shirt: https://teespring.com/stores/making-the-internet-awesome
💖 Support me on Patreon: https://www.patreon.com/kevinpowell
---
My editor: VS Code - https://code.visualstudio.com/
---
I'm on some other places on the internet too!
If you'd like a behind the scenes and previews of what's coming up on my YouTube channel, make sure to follow me on Instagram and Twitter.
Instagram: https://www.instagram.com/kevinpowell.co/
Twitter: https://twitter.com/KevinJPowell
Codepen: https://codepen.io/kevinpowell/
Github: https://github.com/kevin-powell
---
And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Kevin Powell · Kevin Powell · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
How to create an awesome navigation bar with HTML & CSS
Kevin Powell
Improve your CSS by Keepin' it DRY
Kevin Powell
HTML & CSS for Beginners Part 6: Images
Kevin Powell
HTML & CSS for Beginners Part 7: File Structure
Kevin Powell
HTML & CSS for Beginners Part 4: Bold and Italic text and HTML comments
Kevin Powell
HTML & CSS for Beginners Part 5: Links
Kevin Powell
HTML & CSS for Beginners Part 3: Paragraphs and Headings
Kevin Powell
HTML and CSS for Beginners Part 1: Introduction to HTML
Kevin Powell
HTML and CSS for Beginners Part 2: Building your first web page!
Kevin Powell
HTML & CSS for Beginner Part 8: Introduction to CSS
Kevin Powell
HTML & CSS for Beginners Part 9: External CSS
Kevin Powell
HTML & CSS for Beginners Part 10: Divs & Spans
Kevin Powell
HTML & CSS for Beginners Part 11: Classes & IDs
Kevin Powell
HTML & CSS for Beginners Part 12: The CSS Box Model - Margin, Borders & Padding explained
Kevin Powell
HTML & CSS for Beginners Part 13: Background Images
Kevin Powell
HTML & CSS for Beginners Part 14: Style Text with CSS
Kevin Powell
HTML & CSS for Beginners Part 15: How to style links
Kevin Powell
HTML & CSS for Beginners Part 16: CSS selectors and Specificity
Kevin Powell
HTML & CSS for Beginners Part 17: How to Create and Style HTML Lists
Kevin Powell
HTML & CSS for Beginners Part 18: How Floats and Clears work
Kevin Powell
HTML & CSS for Beginners Part 19: Colors with CSS - hex, rgba, and hsla
Kevin Powell
HTML & CSS for Beginners Part 20: How to center a div
Kevin Powell
HTML & CSS for Beginners Part 21: How to create a basic website layout - the HTML
Kevin Powell
HTML & CSS for Beginners Part 22: How to create a basic layout - the CSS
Kevin Powell
How to Create a Responsive Website from Scratch - Part 1: The HTML #Responsive #HTML5
Kevin Powell
How to Create a Responsive Website from Scratch - Part 2: The Header and Hero area #Responsive #CSS3
Kevin Powell
How to Create a Responsive Website from Scratch - Part 3: The About Section #Responsive #CSS
Kevin Powell
How to Create a Responsive Website from Scratch - Part 4: Building a Responsive Portfolio Section
Kevin Powell
How to Create a Responsive Website from Scratch - Part 5: Call To Action and Footer #CSS #Responsive
Kevin Powell
Tutorial: Learn how to use CSS Media Queries in less than 5 minutes
Kevin Powell
End of the year upate and what's coming to my channel to start the new year
Kevin Powell
Create a CSS only Mega Dropdown Menu
Kevin Powell
CSS Tutorial: Outline and Outline Offset
Kevin Powell
CSS Blending Modes
Kevin Powell
Parallax effect | 2 different ways to add it with jQuery
Kevin Powell
CSS Units: vh, vw, vmin, vmax #css #responsive #design
Kevin Powell
How to Create a Website - Complete workflow | Part 01: Intro + Setting things up
Kevin Powell
100 Subscribers speed coding bonus video
Kevin Powell
How to Create a Website - Complete workflow | Part 02: The Markup #HTML
Kevin Powell
How to Create a Website - Complete workflow | Part 03: Sass Variables and a Mixin #Sass
Kevin Powell
How to Create a Website - Complete workflow | Part 04: Setting up the hero and header
Kevin Powell
How to Create a Website - Complete workflow | Part 05: Typography & Buttons
Kevin Powell
How to Create a Website - Complete workflow | Part 06.1: Building the navigation with Flexbox
Kevin Powell
How to Create a Website - Complete workflow | Part 06.2: Making the nav work with jQuery
Kevin Powell
Redesigning & Coding My Website #CreateICG
Kevin Powell
How to Create a Website - Complete workflow | Part 07: Starting the flexbox grid
Kevin Powell
How to Create a Website - Complete workflow | Part 08: Promo & Problem shooting!
Kevin Powell
How to Create a Website - Complete workflow | Part 09: The CTA and Footer
Kevin Powell
How to Create a Website - Complete workflow | Part 10: Making it responsive
Kevin Powell
How to Create a Website - Complete workflow | Part 11: Making it responsive con't
Kevin Powell
How to Create a Website - Complete workflow | Part 12: Putting the site online
Kevin Powell
Create a Custom Grid System with CSS Calc() and Sass
Kevin Powell
CSS em and rem explained #CSS #responsive
Kevin Powell
Should you use Bootstrap?
Kevin Powell
How to add Smooth Scrolling to your one page website with jQuery
Kevin Powell
Let's learn Bootstrap 4
Kevin Powell
How I approach designing a website - my thought process
Kevin Powell
Build a website with Bootstrap 4 - Part 1: The setup
Kevin Powell
Build a website with Bootstrap 4 - Introduction
Kevin Powell
Build a website with Bootstrap 4 - Part 2: Customizing Variables
Kevin Powell
More on: HTML & CSS
View skill →Related Reads
📰
📰
📰
📰
Three Token-2022 Mints in One Week: Fees, Yield, and Soulbound
Dev.to · atharv shukla
Maximize Google Workspace AI Power: Safeguard Data and Boost Performance in 2026
Dev.to AI
What is Gemini Spark, and what can it actually do for you?
TechCabal
How I use python to save hours every week
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI