You Probably Need BEM CSS in Your Life (Tutorial)

Тәжірибелік нұсқаулар және стиль

Visit linode.com/designcourse for a $20 credit on your new linode account.
designcourse.com - Learn UI/UX from Scratch with my new service (coming soon)
-- Today, we're going to cover the BEM method for writing CSS. BEM is an acronym for Block Element Modifier, and it's an approach to defining and structuring your CSS. When you're dealing with medium to large size projects, it helps you develop a maintainable code base and one that doesn't run into issues with specificity. While this is a beginner's level tutorial, we will be jumping into more intermediate and advanced tutorials later on down the road.
Codepen demo for this tutorial:
codepen.io/designcourse/pen/K...
Let's get started!
- - - - - - - - - - - - - - - - - - - - - -
Subscribe for NEW VIDEOS!
My site: designcourse.com
My personal FB account: logodesigner
Coursetro FB: coursetro
Coursetro's Twitter: / designcoursecom
Join my Discord! / discord
^-Chat with me and others
- - - - - - - - - - - - - - - - - - - - - -
Who is Gary Simon? Well, I'm a full stack developer with 2+ decades experience and I teach people how to design and code. I've created around 100+ courses for big brands like LinkedIn, Lynda.com, Pluralsight and Envato Network.
Now, I focus all of my time and energy on this channel and my website Coursetro.com.
Come to my discord server or add me on social media and say Hi!

Пікірлер: 365

  • @DesignCourse
    @DesignCourse4 жыл бұрын

    Enjoooy?? Subby subby!

  • @GammaWraith

    @GammaWraith

    4 жыл бұрын

    I did.. Coursy? Coursy?

  • @lucianoramirez6525

    @lucianoramirez6525

    4 жыл бұрын

    as always so useful, but I have a question not entirely related. How could one get around having to get the back-end done yourself, and instead just have e.g. an email submission form made with an API? Could that be possible? If so how? Because I actually built a sort of fully-blown html and css project with different urls but my goal for this website is for it to get people submit their email to apply and stuff, but that would require some kind of back-end. Would it not? Hope I explained myself clear enough, sorry if not. Thanks again!

  • @juraev0056

    @juraev0056

    4 жыл бұрын

    @@lucianoramirez6525 Yes it does require some backend if you want people to sign up to apply for something. If you just want a contact form that sends you a user message from your website, its very easy to do.

  • @xrishi20

    @xrishi20

    4 жыл бұрын

    It's live sass compiler, not compilation i guess 🤭

  • @Saaztube

    @Saaztube

    4 жыл бұрын

    Had to subscribe. Thanks.

  • @yvonniie
    @yvonniie3 жыл бұрын

    I want a Part 2 where you go more in depth with a bigger project!

  • @georgemallard4120
    @georgemallard41204 жыл бұрын

    I am a CSS newbie. The way he showed BEM using the $ helped me understand the cascade in CSS. Thanks!

  • @aspected
    @aspected4 жыл бұрын

    I've actually been really enjoying your videos and I've watched quite a few since I found your channel the other day. A lot of stuff I've watched has been beginner-intermediate level but it doesn't feel like I'm missing anything I _must_ already know because you don't speak down to your viewer, which is really nice! Some channels kind of act like they're the best and everyone else sucks, so it's nice to watch videos where I can actually learn and feel like I'm getting somewhere with this.

  • @CODINGVENTURE
    @CODINGVENTURE4 жыл бұрын

    I'm mad he never noticed that he added a class to the end of the list item tag

  • @1997matthew

    @1997matthew

    4 жыл бұрын

    It's the Auto Rename Tag plugin that's doing that

  • @CODINGVENTURE

    @CODINGVENTURE

    4 жыл бұрын

    @@1997matthew I know I'm just mad he didn't notice lol

  • @local9

    @local9

    4 жыл бұрын

    You got mad at that... I got mad at calling Underscores (_) as Hyphens (-) and Hyphens as Dashes >.

  • @physx_naraka

    @physx_naraka

    4 жыл бұрын

    I was about to raise my hand and tell him that, thought it was a real-life lecture .

  • @estoriassurreais3434

    @estoriassurreais3434

    4 жыл бұрын

    @@1997matthew thanks

  • @ihajo
    @ihajo4 жыл бұрын

    Great video as usual.. I love these fast short and on point.. keepem coming

  • @JPierro
    @JPierro4 жыл бұрын

    You are really good at explaining these things. You rock.

  • @klingonac79
    @klingonac794 жыл бұрын

    Best BEM explanation so far

  • @n4botz
    @n4botz4 жыл бұрын

    I personal use BEM together with OOCSS any projects and it's for me a game changer. Simply clean structured and easy to read CSS. Keep up the good work! Regards from germany!

  • @jenninexus
    @jenninexus4 жыл бұрын

    This is my new favorite channel :-D Thanks for all the great knowledge

  • @akashbond862
    @akashbond8624 жыл бұрын

    Came here after watching Kevin Powell's video on BEM. There he had said "specificicity", and here Gary says "specifity". Guess Kevin stole Gary's "ci".

  • @RainOnline

    @RainOnline

    3 жыл бұрын

    lolol

  • @gabrielsequeira-bacher9049

    @gabrielsequeira-bacher9049

    3 жыл бұрын

    😂

  • @AverageCho

    @AverageCho

    3 жыл бұрын

    me reading your comment: specifi-kitty...dammit

  • @UnknownUser-ts1sw

    @UnknownUser-ts1sw

    3 жыл бұрын

    wtf😂

  • @dasunanushka8774
    @dasunanushka87744 жыл бұрын

    Best explanation with an example. Thanks.

  • @nikolozmacharashvili1212
    @nikolozmacharashvili1212 Жыл бұрын

    great job with the slides... best slides I have ever seen

  • @jennisonb37
    @jennisonb379 ай бұрын

    Thank you for explaining BEM so clearly and succinctly. You got a new sub and I'm looking forward to watching some of the other videos you have.

  • @mirza4477
    @mirza44773 жыл бұрын

    Awesome, simple explanation in less than 20 minutes!

  • @nurullokhuvaidullaev9684
    @nurullokhuvaidullaev96843 жыл бұрын

    Awesome job! Thanks, Gary🙌🏿

  • @speedhaak
    @speedhaak4 жыл бұрын

    Great video, enjoyed the insight. Will try this out on our next project, cheers!

  • @souravsinha5330
    @souravsinha53303 жыл бұрын

    Thanks a lot sir. Really helped me a lot to understand it from scratch. I'm very much new to this SCSS and BEM concept

  • @parthkumarchaudhary
    @parthkumarchaudhary4 жыл бұрын

    Tutorial on time. Thank you Gery Teacher. :)

  • @sahilgarg1924
    @sahilgarg19243 жыл бұрын

    It was great! Improved my method of coding CSS!

  • @andreppg
    @andreppg2 жыл бұрын

    Great tutorial ! Good speed, clean and straightforward to the point. Thanks.

  • @GamingTSH

    @GamingTSH

    2 жыл бұрын

    🙏❤️kzread.info/dash/bejne/nqF92buFdrzAabg.html❤️🙏

  • @karldtrumpeter
    @karldtrumpeter3 жыл бұрын

    Couldn't be more explicit. Thank you!

  • @vito-mohagheghian
    @vito-mohagheghian Жыл бұрын

    the best BEM tutorial

  • @AdyB2008
    @AdyB20082 жыл бұрын

    Great easy to understand video. Thank you!

  • @leonbenjamin7891
    @leonbenjamin78913 жыл бұрын

    Excellent video to understand BEM methodology. Thanks!

  • @rafaellerescapone
    @rafaellerescapone4 жыл бұрын

    if i wasnt already using React+Styled Components to deal with such issues, this looks like an amazing system to solve such problems in a practical and DX friendly way

  • @mrsingh5351
    @mrsingh53513 жыл бұрын

    So much style in your videos, it's actually delicious!

  • @afique8932
    @afique89324 жыл бұрын

    Very good explanation. Thank you!

  • @andresfrr100
    @andresfrr1003 жыл бұрын

    Thanks! A really good example of using BEM.

  • @kory3762
    @kory37624 жыл бұрын

    Great Tutorial DesignCourse!!!

  • @ChrisAthanas
    @ChrisAthanas3 жыл бұрын

    Solid clear explanation

  • @briankgarland
    @briankgarland4 жыл бұрын

    Thanks! I got put onto a project late in development and found all these classes written like this and didn’t know what the heck was going on.

  • @Vittokm
    @Vittokm9 ай бұрын

    Very very good! was trying to understand this before but only now I understand :)

  • @dilinirajapaksha
    @dilinirajapaksha2 жыл бұрын

    Very helpful, great tutorial. Thank you!!!

  • @DavidJonathan10
    @DavidJonathan103 жыл бұрын

    Thanks for all your great content always.

  • @TineruHarlem
    @TineruHarlem2 жыл бұрын

    Thank you for a good explanation! This video helped a lot!

  • @rosstee
    @rosstee3 жыл бұрын

    Thanks for a great intro to BEM. I used to do HTML/CSS years ago and need to pick it back up at work. These days my company uses BEM and SASS so this was perfect and very easy to follow.

  • @ilyasseisov7204
    @ilyasseisov72043 жыл бұрын

    Thank you Gary!

  • @sojibhasan1380
    @sojibhasan13803 жыл бұрын

    This video is very helpful especially for me.

  • @AstroSirrus
    @AstroSirrus3 жыл бұрын

    Bem Bem... What a Bem Bem! 💎 Thanks for this great tutorial! 🤗🤗🤗

  • @amirfayazi562
    @amirfayazi5624 ай бұрын

    Thanks for such a helpful video

  • @crooker2
    @crooker24 жыл бұрын

    Specificity... Pronounced: spes-ih-FISS-city (5 syllables) :) Good video. I don't use BEM currently, but I'm going to play with it.

  • @sanketmane5838
    @sanketmane58382 жыл бұрын

    Thank you so much for this tutorial...

  • @yashkadam278
    @yashkadam2784 жыл бұрын

    Thanks for making a video on this topic.....

  • @simonkalu
    @simonkalu4 жыл бұрын

    Awesome! Thanks for your time

  • @flowerofash4439
    @flowerofash44392 жыл бұрын

    nice method on writing css, scss + bem probably the best way to go for large project

  • @BenRangel
    @BenRangel4 жыл бұрын

    One piece of advice is: don’t forget utility-classes just cause you use BEM! A ”hidden” class makes more senese than having a ton of modifier classes that do the same thing, like ”card-hidden” and ”article-hidden” Only use BEM for unique styles and not common ones. You can combine BEM and utility classes, no need to go 100% in a single direction. doing ”card card-large hidden” is fine

  • @mariodakhil7805
    @mariodakhil78054 жыл бұрын

    this is so helpful , i understand them here better than my teacher

  • @adventure-007
    @adventure-0074 жыл бұрын

    Done that loooong ago. Best decision!

  • @truvc
    @truvc4 жыл бұрын

    Styled components are the bomb. Svelte and react have completely made BEM obsolete from my life and I love it

  • @gajendra1987
    @gajendra19873 жыл бұрын

    Good content, liked and subscribed. All the best!!

  • @santosfernandotinga7773
    @santosfernandotinga77734 жыл бұрын

    thank you! I loved this video

  • @BenRangel
    @BenRangel Жыл бұрын

    I've used BEM for many years. Modifiers are great and truly provides a nice way of stating a clear intention that this element has a shared base style and a variant that overrides or adds a few things. But the block__element concept is less useful. It's fine in tiny flat components that you don't change a lot. But in larger things the double underscore often has to be moved deeper down and feels useless. You begin with footer__menu but as that menu gets more and more children you rename it to footer-menu so can have children like footer-menu__user and footer-menu__faq If this renaming happens multiple times, or the dom tree for the footer is quite deep then you end up just forgetting which nodes have the block__element thing and which just use dashes. At which point I usually go "screw it, let's use single dashes all the way" and I never end up regretting it. I still use BEM on small isolated components though.

  • @gazza363
    @gazza3632 жыл бұрын

    Fantastic video

  • @deniskotov
    @deniskotov3 жыл бұрын

    Cool stuff!

  • @MarleyAnthony
    @MarleyAnthony4 жыл бұрын

    Great video, thanks a lot!

  • @naturalbornchiller158
    @naturalbornchiller1584 ай бұрын

    Thanks dude!

  • @meirunassmitas8762
    @meirunassmitas87624 жыл бұрын

    Helps to understand BEM !

  • @esportsnexus
    @esportsnexus4 жыл бұрын

    Awesome Garry

  • @alexanonymous5823
    @alexanonymous58233 жыл бұрын

    thanks for BEM explanation=))

  • @chriscarton4728
    @chriscarton47284 жыл бұрын

    Stunning.

  • @USONOFAV
    @USONOFAV4 жыл бұрын

    Been like doing this, but without those double underscores and double dash for modifiers. However, thank you for showing this.

  • @chesb6426
    @chesb64263 жыл бұрын

    thanks for this

  • @AcademyOmen
    @AcademyOmen3 жыл бұрын

    Great 💡, thanks

  • @jayandrews2358
    @jayandrews23584 жыл бұрын

    Very good. Thanks

  • @claudiutamas79
    @claudiutamas79 Жыл бұрын

    GEnial! Thanks!

  • @zayarlyn
    @zayarlyn2 жыл бұрын

    gonna follow that convention

  • @0neonited463
    @0neonited4634 жыл бұрын

    Been using BEM method for over 2 month now... But thanks for reminding how it is..

  • @ufufu001
    @ufufu0013 жыл бұрын

    This is *perfect* ! I'm gonna be using it even if the project is small. My CSS naming is a mess and this makes it super organized and coherent. THANK YOU

  • @lufefe543
    @lufefe5432 жыл бұрын

    thanks a lot!

  • @stasmaksimov9531
    @stasmaksimov95314 жыл бұрын

    Great! Thanks a lot! 🤝👍

  • @mouayadmmouayad3106
    @mouayadmmouayad31063 жыл бұрын

    thank youuuu man

  • @EvaLasta
    @EvaLasta3 жыл бұрын

    Man you got such a unique vocabulary haha 1:02 "specifity" 3:14 "complexitness" I think you mean specificity and complexity lol I love your videos btw Im just playing around.

  • @rand0mtv660

    @rand0mtv660

    3 жыл бұрын

    The second was was him saying "a little bit more complex than this".

  • @kastus9188
    @kastus9188 Жыл бұрын

    great video

  • @kzar123
    @kzar1233 жыл бұрын

    Great video. Subscribing now

  • @babayaga5848
    @babayaga58484 жыл бұрын

    great stuff simon, can you please make a video that explain how to configure php for vsCode, so it can auto complete and other things like the atom built-in feature

  • @basith237
    @basith2374 жыл бұрын

    Thanks

  • @angadgraphics
    @angadgraphics3 жыл бұрын

    Thanks sir :)

  • @ishaankarnik6136
    @ishaankarnik61362 жыл бұрын

    thanks!

  • @Gigusx
    @Gigusx4 жыл бұрын

    I got into TailwindCSS before getting interested in BEM, so I never really ended up needing it. A useful video nonetheless for a quick overview!

  • @Gigusx

    @Gigusx

    4 жыл бұрын

    @Library Content Yeah, me as well! The nesting of SASS makes it all look very clean and easy to modify.

  • @Arttyor

    @Arttyor

    4 жыл бұрын

    Tailwind is framework tho, this is just methology

  • @Gigusx

    @Gigusx

    4 жыл бұрын

    @@Arttyor That's right, but it removes the necessity for using a naming methodology, at least when you follow the similar process that Adam Wathan (Tailwind's author) does.

  • @davidnagy1046
    @davidnagy10464 жыл бұрын

    thank you for the video! will you cover CSS-in-JS sometime soon?

  • @rogaldorn7016
    @rogaldorn70164 жыл бұрын

    Wow, one of the best practices! I love to use it with SASS or LESS! It makes writing your code much easier. Hovewer, BEM classes can be really long sometimes (class="card__heading card__heading--available main__card")

  • @ead5590

    @ead5590

    4 жыл бұрын

    So true about it being long.. Sometimes I myself would forget what was the modifier I used.. 🤣 Then I'd have to browse through the entire HTML file looking for what I need to work on..

  • @rogaldorn7016

    @rogaldorn7016

    4 жыл бұрын

    @@ead5590 or sometimes you can have similar classes 🤣 Especially, when your project as big as f...

  • @ead5590

    @ead5590

    4 жыл бұрын

    @@rogaldorn7016 Definitely. That's very possible. And that is probably one of the reasons why we use stuff like BEM so that we don't have such issues. Then again, it's a matter of preference. If someone would like to use methodologies such as BEM or not, it's clearly up to the Developer.

  • @BenRangel

    @BenRangel

    4 жыл бұрын

    Why would you have one element be both "main__card" and "card__heading"? That doesn't make sense. Either it's a card or a heading for a card. Not both at the same time.

  • @rogaldorn7016

    @rogaldorn7016

    4 жыл бұрын

    @@BenRangel yah, my bad. It should sound like "card main__card main__card--active"

  • @amanvishwakarma7847
    @amanvishwakarma78474 жыл бұрын

    Most of the things i learned from here ☺️

  • @alex_chugaev
    @alex_chugaev4 жыл бұрын

    I'm so happy Angular has styles isolation mechanism and I don't need to use BEM anymore :D

  • @Zach2825

    @Zach2825

    4 жыл бұрын

    Vue has that too. It is so convenient

  • @diablo.the.cheater

    @diablo.the.cheater

    4 жыл бұрын

    @Angelo Stevens overkill is a feature not a bug

  • @ShadiMuhammad

    @ShadiMuhammad

    4 жыл бұрын

    @@diablo.the.cheater 😂😂

  • @etmargallo

    @etmargallo

    3 жыл бұрын

    Do you guys mean “scoped”?

  • @AllenMarsam
    @AllenMarsam4 жыл бұрын

    thanks

  • @sunflair-wa
    @sunflair-wa2 жыл бұрын

    Thank you so much. I feel like I have been given the secret handshake to the club :)

  • @GamingTSH

    @GamingTSH

    2 жыл бұрын

    🙏❤️kzread.info/dash/bejne/nqF92buFdrzAabg.html❤️🙏

  • @howiewang4238
    @howiewang42383 жыл бұрын

    Thank you for this tutorial. In the beginning, why do we need two underscores for Class name instead of one underscore, which is simpler and more efficient?

  • @piorun1316
    @piorun13164 жыл бұрын

    I heard a lot about BEM and then I discovered TailwindCSS which is mega cool. Worth checking out :)

  • @simpleprogramming4671
    @simpleprogramming46714 жыл бұрын

    Design Course thank you so much for your amazing tutorials. Your Videos are really unique. I have a question, when a block gets very big(when I start a big project it gets really confusing for me how to break it to smaller blocks and elements. does anybody have any suggestions? Thank you all in advance :)

  • @danteelegante4601
    @danteelegante46013 жыл бұрын

    Omg you get a thumbs up on this video my friend especially after you said "You better not leave". 😂 That moment definitely made me laugh so hard but also made me want to stick around to the end. Thanks for having an awesome sense of humor while teaching. 💜

  • @lennart5845
    @lennart58454 жыл бұрын

    I’ve been using it just because I saw that JetBrains has it on the webpage. Now I see why I’m doing it

  • @notkamui9749

    @notkamui9749

    4 жыл бұрын

    I like the fact that you follow JetBrains :)

  • @AndiRadyKurniawan

    @AndiRadyKurniawan

    4 жыл бұрын

    Why is that? What's the benefit?

  • @lennart5845

    @lennart5845

    4 жыл бұрын

    Andi Rady Kurniawan if you’re using scss, which will definitely help you a lot, this Bem makes it easier. You can type .menu and in scss the „&“ character selects it again but you can add something. So for example if you have a list in your menu which has the class „menu__list“ you can just type in the menu css: &__list (.menu__list). And that with several items. It just helps you a lot and organizes everything

  • @goshmain982
    @goshmain9824 жыл бұрын

    Please release advanced BEM

  • @yasinkarimzadeh
    @yasinkarimzadeh2 жыл бұрын

    perfect

  • @harinarayanan6780
    @harinarayanan67803 жыл бұрын

    Awesome

  • @rhcarlosweb
    @rhcarlosweb4 жыл бұрын

    One interesting too is RSCSS method

  • @chrisandrew_tv
    @chrisandrew_tv4 жыл бұрын

    BEMs weakness, if there’s one to be extracted from these comments, is its name. Blocks, elements; most of these people know what those are and that can make it confusing when there are more than 2 nest levels. What I take away from this is that it’s definitely useful if used thoughtfully, when considering the first slides: What blocks on are project are similar in HTML structure but unique in content nature or styling? Card, content, list, these terms are general but if I imagine a blog post preview, album preview, news article preview or rental listing, I can see how BEM would be beneficial. Thank you.

  • @jojo_Ca
    @jojo_Ca4 жыл бұрын

    Great vid thank you, what compiler are you using and how are you watching your files?

  • @maxmaksum4673
    @maxmaksum46733 жыл бұрын

    awesome

  • @devKazuto
    @devKazuto4 жыл бұрын

    I'm not a fan of BEM. I prefer using utility classes instead of --modifier. Most IDE don't have a problem selecting "card-header" on double click, but will struggle with "card__header". Having an arbitrary long class name will also increase file size. We're removing line breaks and spaces on minification, but 30 letters long classes are fine.

  • @BenRangel

    @BenRangel

    4 жыл бұрын

    Kazu: which IDE? i thought most had a hotkey to select by free text search. I use vscode and I use cmd+d to select any string by free text search

  • @BenRangel

    @BenRangel

    4 жыл бұрын

    What do you mean by arbitrarily long? In BEM the idea is you can only have a single level: card__header is ok but card__header__title or card__header__title__icon is banned

  • @devKazuto

    @devKazuto

    4 жыл бұрын

    @@BenRangel I'm talking about double click text selecting, not hotkey. Some don't see cohesion of a string like "abc--xyz". Having class="button button--state-success" creates a larger filesize in HTML than class="button success". In CSS it's the same. .button-state-success are more characters than .button.success and therefor results in a larger filesize.

  • @kootahaitoo

    @kootahaitoo

    4 жыл бұрын

    @Angelo Stevens yeah file size is like the last reason i would worry when dealing with BEM and CSS

  • @alexsmith-rs6zq

    @alexsmith-rs6zq

    3 жыл бұрын

    Why not both? I’ve recently started using a combination of utility classes for shared styles and BEM for unique styling. It seams to be working well so far.

  • @local9
    @local94 жыл бұрын

    I'll stick to Tailwind CSS mainly, BEM is handy for other things but aye, might use it one day.

  • @LuBre

    @LuBre

    4 жыл бұрын

    Watching the code example on Tailsiwn'ds homepage made me cry. The amount of inline code is insane.

Келесі