Build a responsive, animated, accessible accordion that looks pretty good

Поділитися
Вставка
  • Опубліковано 2 лис 2024

КОМЕНТАРІ • 124

  • @front_coding
    @front_coding Рік тому +39

    Your channel inspired me to start my own front end development channel, thanks for your amazing content kevin ♥

    • @CMB696
      @CMB696 Рік тому +2

      Many of us

  • @SillyCar91
    @SillyCar91 Рік тому +34

    Kevin I just wanted to say thank you for your amazing content. I hated CSS back when I did some web development courses at university a decade ago and after finding your channel 2 years ago you have made me fall in love with it and help me decide to try and work towards a career as a Front End Developer. Love from Australia 🤟

    • @KevinPowell
      @KevinPowell  Рік тому +2

      That's awesome to hear!

    • @CMB696
      @CMB696 Рік тому +2

      That can be anything that we learnt from University or collage will be hated and when some youtuber explains same topic rather than form education perspective will be loved.
      Read twice if u don't get it.

  • @Brunoenribeiro
    @Brunoenribeiro Рік тому +10

    Your dedication to a11y is unique and inspiring in this community, Kevin! Thanks a lot for that

  • @BO-ny5mm
    @BO-ny5mm Рік тому +3

    There is so much to learn from Kevin's videos. Accessibility is explained in full depth, which is often omitted in tutorials. My favorite svg styling, sizing, and adding it as a sprite (been looking for how to do that properly). How and why we could use private CSS variables, JavaScript functionality. It is incredible how much we can learn from only one video. Thank you for the effort you put into your videos, Kevin!

  • @kopilkaiser8991
    @kopilkaiser8991 3 місяці тому

    I absolutely love and cherished this tutorial. I've learnt a lot practising these techniques.

  • @henaorth
    @henaorth Рік тому +1

    I can't listen english very well but your hand gesture is much enough to understand
    I am following your videos since 6 months ago you made me confident on building css projects
    Love you from Ethiopia 🇪🇹

  • @Rottenbrownkid
    @Rottenbrownkid Рік тому

    The universe handed me this at the perfect time. I was looking up how to accordions responsive JUST this morning. Thank you so much !

  • @clevermissfox
    @clevermissfox Рік тому +1

    That isolation property is very interesting, I’ve watched your vids on z index and would love more about stacking context and that isolation property!

  • @ThomasProsserZurich
    @ThomasProsserZurich Рік тому

    Up until now, I hated acccordions for precisely the reasons you mentioned in the beginning. Thanks for changing my mind! This is beautiful!

  • @jevessonsouza7947
    @jevessonsouza7947 Рік тому

    A HUGE THANK YOU from Brasil!!!
    For this and all other videos from your channel!

  • @warkentien2
    @warkentien2 Рік тому +2

    Another great tutorial Kevin!
    - Interesting CSS variable with underscore take; I like it.
    - Great use case for flex-basis.
    - first time hearing about isolation: isolate and contain: content!

  • @ichiroutakashima4503
    @ichiroutakashima4503 Рік тому +2

    Thanks for this neat tutorial, Kevin! I really love it. I hope you make more contents, especially on topics about images and web development. I always find it hard making an image properly responsive especially when a client gives you ridiculous and inconsistent image resolutions.

  • @Anth-ony
    @Anth-ony Рік тому +2

    Really loved this video. Well thought out and the result is pretty good looking/functioning. More of these please.

  • @amanuelelhanan4716
    @amanuelelhanan4716 Рік тому +1

    Isolation: isolate ohh Kevin this was a mystery to me and you enlightened me today.

  • @anatanhofer3191
    @anatanhofer3191 Рік тому

    Definitely one of my favourite videos and thank you for sharing the final code. Really enjoyed to follow the class with html, css in js doc in front.

  • @avneet12284
    @avneet12284 Рік тому +1

    Hard to follow without code. Excellent stuff, regardless, Kevin

  • @ThomKnepper
    @ThomKnepper Рік тому

    Kevin, you're an absolute genius! Thanks for explaining so well.

  • @kesvalsensei8251
    @kesvalsensei8251 Рік тому +1

    1h20 of video, great accordion, great content, I mean I just love you at this point Kevin.

  • @zeddash
    @zeddash Рік тому +2

    Huge improvement to turn a functional concept into something that can actually be used. It's worth keeping in mind that while you're free to use content published on CodePen‡ many of the designs are first draft with minor tweaks, and do not adhere to the standards you would expect from a website. We boil down the thing we want to show off into the simplest form with only what is necessary, and important aspects such as accessibility are overlooked. When I make a pen I use it as a learning experience both for myself (many pens are an exploration of just a couple CSS properties and how they work together) and others, and I produce work that you can't just copy and paste.
    I've recived a lot of messages from people asking me how to paste many of my works, with many specifying this accordion into their website and they missed the point. This video is a beacon for how to use and improve a pen, really happy that you chose mine to use as inspiration.
    -Zed Dash
    ‡designs may be protected (avoid anything that is marked as a logo), you are free to use the code itself. You generally can modify the design into its own thing and it's fine. The license for pens can be found at the bottom of the details page. Be aware that some pens use designs from Dribbble shots, these should be linked in the pen's description in which case you cannot keep the same design. Don't think that people won't notice, designers are very aware of the designs others make and we're quick to message the designer about someone using their design.

  • @Arcanist1010
    @Arcanist1010 Рік тому

    I remember that I always visited this channel when I am learning HTML/CSS, then after I moved to Javascript I never came back in this channel but today I cameback to CSS/HTML and I am excited to watch your videos again.
    I hope you will upload JS related video.

  • @johnKeysCloudSonics
    @johnKeysCloudSonics Рік тому +1

    To remove the outline on the panel when the button is clicked I did the following:
    .accordion-panel:focus-within:has(.accordion-trigger:focus-visible) {
    outline: 3px ridge var(--_panel-color);
    outline-offset: 4px;
    }
    I then used the `.accordion-panel:has([aria-expanded='true'])` selector to add a box-shadow to the expanded panel (using the panel color variable).

  • @SebastianZartner
    @SebastianZartner Рік тому

    Kevin, first of all a big thank you for walking through this task step by step! With that, it is very easy to comprehend how this is done.
    One little note, on 45:05, you could also have used `querySelector('button[aria-expanded="true"])` to just get the one you want to toggle to `false`. This works similar for the contents, as well.

    • @KevinPowell
      @KevinPowell  Рік тому

      Oh, for sure! I did it in a bit more of a lazy way in having one less thing to query (though I did have to make a loop, so 🤷). I don't think you'd really see a performance issue one way or the other, but if it was something that had like 50 panels, it'd probably be best to only select the one you actually want... but then I'd question the design decision of having a 50-panel accordion 😅

  • @stonedizzleful
    @stonedizzleful Рік тому

    Just followed this through. So thorough and well described. Thank you!!

  • @j-janz
    @j-janz Рік тому

    27:56 It's from my own experience, too, also from the top of *my* head (so it could not be the first use of it),, but I've first seen prefixing private members with underscores way back when learning python in around 2005/2006, being a good practice there, mainly because it didn't actually have strict private members, so it would indicate to whoever extending the class that it was a private member.

  • @CirTap
    @CirTap Рік тому

    #25:30 replacing elements like svg, (and Netscape's layer), object, embed, all share that same intrinsic default size. It's from the olden days of html3 and html4 if one does not provide the width/height attributes. Someone in the 90ies at W3C just decided those were great defaults. Also screens where much smaller then, so 300x150 could possibly fill half the window.
    Later additions just "inherited" these already standardized default sizes. I believe video w/o the attributes also defaults to this.

  • @kappesante
    @kappesante Рік тому

    you are one of the two most valuable kevins on the web. this was damn funny!

  • @Niallphillips
    @Niallphillips Рік тому +6

    Pretty disappointed you didn't tackle the animate to auto-height problem that everyone always has with these things

    • @gykonik
      @gykonik Рік тому +2

      So true, I remember having this problems in the past :/

  • @master3spect
    @master3spect Рік тому

    Kevin thank you so much! It’s amazing!

  • @igorjerkovic4891
    @igorjerkovic4891 Рік тому

    Keep going friend, your videos are inspiring us for sure,and as always we learn something..thank you for sharing your knowledge and creativity with us ❤!

  • @Birke1981
    @Birke1981 Рік тому

    Thanks for this fantastic video! Actually for your whole work here on youtube.

  • @andradegilmar
    @andradegilmar Рік тому

    Fantastic tutorial!

  • @ProfoundKnowledge
    @ProfoundKnowledge Рік тому

    Tks god, this is exactly what I'm looking for after struggling to do it in react

  • @nomad100hd
    @nomad100hd Рік тому

    Every forEach loop raises the big O by a power of 1. I believe the same for every querySelectorAll.

  • @CMB696
    @CMB696 Рік тому +1

    I have to see this video after a year and half 'cause ur videos are futuristic.
    I just saw the video that a ball is bouncing on a cube and the overall things are rotating. I think u posted that video a year ago and at that time I'm learning how to line up things in a single line.
    And now I'm interested to learn how 3d css work. Yeah i realised that i don't know much in 2d😅 after seeing this video.
    Anyways great job;

  • @boris7258
    @boris7258 8 місяців тому

    Came for the accordion, returned with SVG icons technique :D

  • @activepoison
    @activepoison Рік тому

    Great job Kevin! I really hate css but you make me hate css just a little less, very little. Anyway I would suggest add white-space: nowrap to the accordion title because if you have the title with multiple words it will wrap when it is collapsed. Either way as always loved your content.

  • @Tazzad
    @Tazzad Рік тому

    It was while trying to recreate this, that I realised the setting in windows 11 to turn of the horrific animations on windows enables the prefers-reduced-motion in chrome....

  • @CirTap
    @CirTap Рік тому

    Wouldn't this also be a perfect use case for details/summary? You get the "open" attribute for free (less JS required for this combo) and the relationship between title, interaction element and content is implicit too. You also have default keyboard control to open/close. Still need to track the state which one's currently open.
    It would have a different role then.
    I need to check the WGAC guides if they have notes on that somewhere.

  • @spanioulis77
    @spanioulis77 11 днів тому

    Amazing! 👌

  • @MrJettann
    @MrJettann Рік тому +1

    Kevin that was so interesting to watch! Recently i've worked on the similar slider at work and was wondering if is there any solution without hardcoding height for the panels, cause its jumping a little bit, i made it with min-height and it worked fine, but nonetheless, awesome tutorial!

  • @peteremad5228
    @peteremad5228 Рік тому

    love this video

  • @ThugLifeModafocah
    @ThugLifeModafocah Рік тому

    Can you do the material design 3 carousel scrolling??? They have some constraints that makes it very challenging.

  • @KelseyThornton
    @KelseyThornton Рік тому +1

    This is a really great CSS control. I love the border - could you use the hover attribute to allow it to appear when the mouse was moving over the element, I wonder?

  • @xcabcz-xabcz
    @xcabcz-xabcz Рік тому

    perfect.
    thanks for vid

  • @programingwithali2461
    @programingwithali2461 Рік тому

    Thanks kevin

  • @K3K900
    @K3K900 Рік тому

    Great video again Kevin, greetins from Venezuela, if you could make a video on how to make an full screen overlay menu, it would be great, also a video about AnimeJS would be amazing, but again thank you for all your content

  • @mldemigod
    @mldemigod 11 місяців тому

    Kevin ---__pading... my brain WOOOO THX MAster

  • @softmekdeveloper-to5vz
    @softmekdeveloper-to5vz Рік тому

    Amazing content 💪

  • @EscherSketcher
    @EscherSketcher Рік тому +2

    46:19 Great video! Though wouldn’t setting all to false cause an issue if you click the same panel twice. Will it attempt to close then open right back?

    • @emmanuelxs6143
      @emmanuelxs6143 Рік тому +1

      Yeah I wanted to ask about this because you could close a accordion if open it.

    • @KevinPowell
      @KevinPowell  Рік тому +1

      It all happens so fast that it won't do that, but you could also return of they click on the currently open one... This is a bit of a lazy approach, but as long as you don't have a ton of them I don't think you'd ever run into an issue

    • @EscherSketcher
      @EscherSketcher Рік тому

      @@KevinPowell Thanks for clarifying 🙏
      You’re right it’s negligible. I later noticed in the video you clicked an open panel w no issues.

  • @kryllyn
    @kryllyn Рік тому

    I wish you could do some videos about JS for beginners or some articles/course on you website, Kevin :(

  • @MuhammadAkbar-sy7zm
    @MuhammadAkbar-sy7zm 5 місяців тому

    Amazing content, I learned a lot, thank you Kevin

  • @ajaykareer
    @ajaykareer Рік тому

    You are the real god of CSS. ♥️

  • @steveportas7961
    @steveportas7961 Рік тому

    Love it! I have a wee question, and the start you mention using the framework of choice. Have you looked at Astro?

  • @LorenzoDeNato
    @LorenzoDeNato Рік тому

    Amazing job, i would really like to learn more about aria elements but they look kinda confusing, will you ever do something more specific about them?
    Keep on with your work!

  • @dealloc
    @dealloc Рік тому

    Using different colors for focus rings is not good for accessibility. The focus ring should stand out amongst the rest of the content in a consistent way so that it's immediately clear to the user where they are in terms of navigation and interaction. Especially for people with eye deficiencies (color blindness, and blindness in general)
    I suggest always having as much contrast as possible, and in most cases I don't even bother customising it because the user is likely familiar with focus style of their browser or OS. This is also why there are values like "-webkit-focus-ring-color" which is dependent on OS settings.

  • @kesvalsensei8251
    @kesvalsensei8251 Рік тому

    At 56:00, why not, instead of padding * 4, do panel-padding + button-size + panel-gap ? That would make it so the spacing on each end of the paragraph is exactly the same

  • @clevermissfox
    @clevermissfox 9 місяців тому

    I used that same a11y page a few months ago to build an accordion and once I was finished , on the example page I THEN saw the warning not to use this code in production 😂

  • @balajishankar
    @balajishankar Рік тому

    Great content as always. Do you normally share code for any of your projects that you demo on UA-cam?

    • @KevinPowell
      @KevinPowell  Рік тому

      Not always, but bigger things I do, not sure why I didn't on this one. Just added the github repo: github.com/kevin-powell/accordion

    • @balajishankar
      @balajishankar Рік тому

      @@KevinPowell thanks so much

  • @astridtonka6762
    @astridtonka6762 Рік тому

    Hey Kevin
    first i wanted to thank you for your inspiring content.
    I love this accordion so much - but - maybe i missed the point or you mentioned it that the accordion doesnt work with firefox.
    Is there a chance to make it work there too?
    Thanks a lot
    Astrid

  • @mhcbon4606
    @mhcbon4606 Рік тому

    why not use some radio/checkbox that uncheck the previous before checking the newer, instead of the added javascript. I believed it would work. It would not ?

  • @realraven2000
    @realraven2000 Рік тому

    I made an accordion within a xul dialog for my Add-on SmartTemplates, but I will soon have to convert the whole thing to html, it's going to be a nightmare because it also has multiple tabs, expanded dialog, multiple decks (one for each mail identity) of tabs, and also uses flex model, just a really really complicated compact tool. Not looking forward to this...

  • @anassekara
    @anassekara Рік тому

    Hello Kevin, I wanted to thank you for your content. Also, I want to suggest a video idea/challenge for you.
    The idea is to create a simple website but not hit save until you finish it and make sure that everything is set, then live server it to see the result. Might be a difficult one, but you got it :D.

    • @KevinPowell
      @KevinPowell  Рік тому +1

      Could be fun, though probably disastrous 🤣

    • @hcx1853
      @hcx1853 Рік тому

      It would be fun for entertainment purposes, and a certain following would find speed-developing tips useful in the trenches - regardless of the technical debt. But in the real-world balance is the key - between innovation and stability.

  • @maxjonas6942
    @maxjonas6942 Рік тому

    Thanks!

  • @emmanuelxs6143
    @emmanuelxs6143 Рік тому

    Kevin you said you could use grid for the image and shouldn't it be --_trigger-gap instead of --_panel-gap.

  • @obsessedprogrammer700
    @obsessedprogrammer700 Рік тому

    Please sir Kevin can you make a video on how to use Vite for file management for beginners?

  • @clevermissfox
    @clevermissfox 9 місяців тому

    Would it be appropriate in this case to make the .accordion-panel itself a button?

  • @juansergiojimenezcanales4923

    At 55:20 could you just change the margin left to a margin-inline ?

  • @ROL4ND-CSS
    @ROL4ND-CSS Рік тому

    One small side note the outline is cutoff because of the "contain: contents" :)

    • @KevinPowell
      @KevinPowell  Рік тому

      Yeah, bit of padding on the entire thing should fix that 🙂

    • @ROL4ND-CSS
      @ROL4ND-CSS Рік тому

      Yes or put the outline offset inside 😊

  • @layer7io
    @layer7io Рік тому

    Hi Kevin, really enjoyed the video, it was a great watch and I followed along for the ride. At the very end you add add the contain: content to the accordion, but unless I'm missing something, the focus rings are now no longer fully visible. Is there a way around that?

    • @KevinPowell
      @KevinPowell  Рік тому

      Oh, I might have missed that! Some padding on the entire element should fix that.

    • @jorgemoreira8721
      @jorgemoreira8721 Рік тому

      There's 2 easy ways of doing it. One is lazy and the other is precise:
      - Lazy: just add padding on "accordion". You can use the panel-padding variable;
      - Precise: create 2 variables for outline and outline-offset and use calc to add them together. In the example of the video each of them have 3px. If you sum them up, you'll get 6px.
      Both of them works well. The precise one just makes sure that if you ever change any of the outline values, it won't break the layout.

  • @mathabahassan3471
    @mathabahassan3471 Рік тому

    Great video! Hope you upload cool JS videos as well :))

  • @vivianliu5011
    @vivianliu5011 Рік тому

    Hi Kevin, just found with the "contain: content;" the focus outline got cut off. do you know the answer for that?

  • @PokemonGo-re7ue
    @PokemonGo-re7ue Рік тому

    Kevin, please do more JS tutorials

  • @luismpcunha
    @luismpcunha Рік тому

    Will this example be available only for patreons?

  • @seanvogel8067
    @seanvogel8067 Рік тому

    Good, but can it play a good polka?

  • @garrycross
    @garrycross Рік тому

    I just got to the .accordian-panel:has([aria-expanded="true"]) { flex-basis section, and the box does not expand in Firefox, but it does in Chrome. Seems like something is not supported.

    • @dealloc
      @dealloc Рік тому +1

      The `has` selector is not supported in Firefox unless you set the `layout.css.has-selector.enabled` flag is set in about:config

    • @garrycross
      @garrycross Рік тому

      @@dealloc I was able to style 2 parts, the p and the img without HAS. But it appears styling accordian-panel size, where you go back a level is not possible with CSS. It's unfortunate that unsupported stuff is used. I don't have the "skills" to fix this. But I will keep it for future reference. At least 12 months after full support in a live site.

    • @dealloc
      @dealloc Рік тому +1

      ​@@garrycross You can get around it by using a polyfill like PostCSS's css-has-pseudo. Of course it requires an extra build step to get there, but if 100% Firefox support is really required for this type of thing, you have to do what you must.

    • @robinhahn6987
      @robinhahn6987 Рік тому

      @@dealloc Thanks for that, mate... the 'has' selector was not working for me in either Firefox or Chrome. Changed this, and it made all the difference. I specifically installed Firefox on my Mac just because Kevin recommended it over other browsers, but this was a bit of a show-stopper. If any other settings need to be changed, then the 'has' selector is a bit ahead of its time. Might go with the Javascript approach. Need to nut that one out, though. 😕

    • @dealloc
      @dealloc Рік тому +1

      @@robinhahn6987 If it didn't work in Chrome you should update your browser asap (not just for :has) but also for security updates.

  • @eduazy
    @eduazy Рік тому

    This can be done with the details tag only, much simpler. I made a CodePen but can't post links here...

    • @KevinPowell
      @KevinPowell  Рік тому

      Yeah, but it's really not accessible. The details tag, while it seems like it could be useful for so many things, tends to actually be pretty limited in what we should actually use it for... This is a nice breakdown of the issues in using it for different use cases - adrianroselli.com/2019/04/details-summary-are-not-insert-control-here.html

  • @enderfun2852
    @enderfun2852 Рік тому

    Yo I also recreated this codepen project for practising my CSS skills

  • @m3vm3
    @m3vm3 Рік тому

    This console.log Js part is giving me trouble. Chrome isn't showing anything, not even an error. just no feedback

  • @CarlosBronze
    @CarlosBronze Рік тому

    is there a codepen with the finished example?

  • @ZackPyle
    @ZackPyle Рік тому

    1:15:28 this is where I wish :focus-visible-within existed

    • @ZackPyle
      @ZackPyle Рік тому

      Thinking about this more, can :has solve this? :has(:focus-visible)

    • @KevinPowell
      @KevinPowell  Рік тому +2

      oh, that would work! Good one :)

    • @ZackPyle
      @ZackPyle Рік тому

      @@KevinPowell I'm not sure if I did it right, but I tried this and it seemed to ignore that it was "focus-visible" and just did it on regular focus too

  • @CuteSkyler
    @CuteSkyler Рік тому +1

    Kevin, can't you use radio buttons and the selected selector so you can make this without js? I'm not sure if you can style radio buttons, though.

    • @JoppeKroon
      @JoppeKroon Рік тому +3

      You may be able to get the same interaction working with radio buttons, but you can't update the aria attributes without JavaScript, so you would be excluding all screen reader users.

  • @zorglub8949
    @zorglub8949 Рік тому

    favicon in svg??

    • @KevinPowell
      @KevinPowell  Рік тому

      Not supportes in Safari sadly. I just use it for my demos starter repo

  • @zorglub8949
    @zorglub8949 Рік тому

    why use "-" and not "_"?

  • @nomad100hd
    @nomad100hd Рік тому +2

    Prettier is to opinionated for my taste. Beautify does everything I want without being arrogant.

  • @n_mckean
    @n_mckean Рік тому

    aria-controls is no shining light. It's got terrible support and so don't rely on it. Old school articles like Heydon Pickering's "aria-controls are poop" are still relevant today.

  • @CarlosAraya25
    @CarlosAraya25 Рік тому

    Be careful when using background images. They are not accessible and assistive technology will not read them

    • @KevinPowell
      @KevinPowell  Рік тому +2

      Totally, that's why I didn't use them here :) - I say you can use them because for something like this, I think the image is a bit more decorative than anything else, but it's easy enough to have as a regular image, so I figured it would be best :)

  • @chukwudobemicah7015
    @chukwudobemicah7015 Рік тому

    Early.

  • @craigsims808
    @craigsims808 Рік тому

    Graceful degradation of an accordion

  • @Boogie63
    @Boogie63 Рік тому

    Würde mich freuen, wenn du auch Worte zu Hunter Biden verlieren würdest und der Rolle von Joe Biden zur Vertuschung der Eskapaden von Hunter und der (damals) bevorstehenden Wahl.

  • @devjyotsidhu820
    @devjyotsidhu820 Рік тому

    I've learnt more from this one video than my entire Software Engineering degree. 🥲

  • @bburgess_keys
    @bburgess_keys Рік тому +2

    OMG, how did I not know about `e.target.closest`????