How to create an Accordion using CSS & Javascript

Enroll My Course : Next Level CSS Animation and Hover Effects
www.udemy.com/course/css-hove...
Another Course : Build Complete Real World Responsive Websites from Scratch
www.udemy.com/course/complete...
------------------
Join Our Channel Membership And Get Source Code of My New Video's Everyday!
Join : / @onlinetutorialsyt
------------------
Patreon : / onlinetutorials
Facebook Page : / onlinetutorialsyt
Instagram : / onlinetutorials_youtube
Twitter : / onlinetutoria16
Website : www.onlinetutorialsweb.com
Buy Me A Coffee : www.buymeacoffee.com/onlineTu...
------------------
give proper credit if you repost this on other social media platform
------------------
Disclaimer video is for educational purpose only. Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for "fair use" for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use

Пікірлер: 143

  • @lernist.oficial
    @lernist.oficial3 жыл бұрын

    I have been watching tutorials for a week, now, at 3am, your video has finally made me finished the final step of my project, thanks a lot man, keep it up

  • @sfrstatus9070
    @sfrstatus90703 жыл бұрын

    Guys an easier method: Heading Lorem Then style it

  • @arkadio638

    @arkadio638

    3 жыл бұрын

    wow so simple :O

  • @sulaimandev

    @sulaimandev

    3 жыл бұрын

    Then how will you learn Javascript?

  • @versatilegeniuses9374

    @versatilegeniuses9374

    3 жыл бұрын

    @@sulaimandev the people who are making projects should learn Javascript first and then come here

  • @HongKong1842

    @HongKong1842

    3 жыл бұрын

    Do you mean it takes fewer DIV ?

  • @wisdomelue

    @wisdomelue

    3 жыл бұрын

    how do you add transitions to this?

  • @kieran2347
    @kieran23473 жыл бұрын

    This is amazing. thanks for this video especially for keeping them short and to the point and ofcourse covering all the parts

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

    A few others have mentioned this. I lose the transition animation when I try to set the active height to 100%, fit-content, or auto. Any solutions? It would be more responsive if the height was dynamic.

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

    Thank you so much for this. Please is there a way to remove the scroll bar, because mine is showing like a dot even when the tab is closed, so the user is able to scroll when the tab is closed from that dot scroll bar... is there a way to remove the scroll bar entirely?

  • @roger6388
    @roger63883 жыл бұрын

    Wow you are the best I have learned many styles of css because of you.Thanks alot 😃 😊

  • @shahadomar4120
    @shahadomar41203 жыл бұрын

    Wow this was so easy and clear , I didn't expect that 😂

  • @RIGARR
    @RIGARR3 жыл бұрын

    thanks bro... I got sucked up here from the last hour and helped me..

  • @appleid3223
    @appleid32232 жыл бұрын

    Very concise. Thanks so much this was really helpful.

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

    Thank yout so much, I made the code in another way but I used yout logic and now my web project is neer to be finished :D, muchas gracias hermano.

  • @CNUVAS0236
    @CNUVAS02363 жыл бұрын

    can u design thumbnail slider/carousel with icons(forward & backward) on top on either right or left?

  • @codecleric4972
    @codecleric49723 жыл бұрын

    Great tutorial, to the point and it works...thank you..

  • @Angryjenkinsdigital
    @Angryjenkinsdigital3 жыл бұрын

    getting bugs on this with iOS/safari - namely issues toggling the active class. Are there known fixes for iOS/Safari?

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

    Thank you, great and simple tutorial.

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

    hey did anyone have any issues with their code? My toggle class doesn't work, everything seems to be fine with the code, but toggle isn't enabled. Any recomms?

  • @tadakuniyasuda8214
    @tadakuniyasuda82143 жыл бұрын

    AMAZING!!!!!!!!!!!!!!!!!!!!!!!!!! Thank you . you are my hero.

  • @webdevwiz5636
    @webdevwiz56362 жыл бұрын

    Amazing work! Thanks for sharing.

  • @anaghakamble1293
    @anaghakamble12932 жыл бұрын

    Amazing video! very helpful, Thanks

  • @user-wx5td9tw2h
    @user-wx5td9tw2h3 жыл бұрын

    Hi! How make accordion in the accordion? Say me please.

  • @soullessleftover8427
    @soullessleftover84273 жыл бұрын

    Say any chance of making a grid like Xiaomi's website for products? Looks really minimalistic and is very polished.

  • @mhassankhan8677
    @mhassankhan86773 жыл бұрын

    what's the use of position:relative in your code? It's everywhere.

  • @shubhamchandel7813
    @shubhamchandel78133 жыл бұрын

    can anyone please explain to me why the "active" class was added before the content. i didn't get the logic. I'm new so it would mean a lot if someone clears this doubt. i don't even know the name of the concept so I cant search the web for it.

  • @maxlong1374
    @maxlong13743 жыл бұрын

    Coding & Piano, best match of all!

  • @chandrakanthpadi
    @chandrakanthpadi3 жыл бұрын

    You are doing an awesome work.

  • @AnjuGupta-jy6lj
    @AnjuGupta-jy6lj2 жыл бұрын

    Which text editor you are using ?

  • @ziledjordjevic695
    @ziledjordjevic6953 жыл бұрын

    Thank you for this tutorial.

  • @yvesyao3529
    @yvesyao35293 жыл бұрын

    You are reading my mind teacher, I was trying to do that too. too loud, thank you teacher

  • @roshansajeev4855

    @roshansajeev4855

    3 жыл бұрын

    Is there a discord channel for online tut

  • @seenuiropias553
    @seenuiropias5533 жыл бұрын

    Thank you. Very useful.

  • @donny533
    @donny5333 жыл бұрын

    awesome! is there a way to make the effects horizontal instead of vertical?

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

    Great tutorial man, that really helped

  • @emcasaempreendimentosimobi3229
    @emcasaempreendimentosimobi32293 жыл бұрын

    thanks, i was in need of that. Gratitude

  • @ahangaraadil
    @ahangaraadil3 жыл бұрын

    That is totally sick. 👨‍💻

  • @Yogibaba_youtubewala
    @Yogibaba_youtubewala3 жыл бұрын

    Awesome as usual

  • @rayjenscode3501
    @rayjenscode35013 жыл бұрын

    nice tutorial. Did you try height 100%? It seems the animation won't effect.

  • @akview6460
    @akview64603 жыл бұрын

    can you make some different nav bar which seems classic and beautiful

  • @doyelbhattacharjee3592
    @doyelbhattacharjee35923 жыл бұрын

    Thank for making this🙏🙏

  • @raguinfotech6639
    @raguinfotech66392 жыл бұрын

    super very use full title thank you

  • @snssatyabhagavan
    @snssatyabhagavan3 жыл бұрын

    I set alarm to see the video first but failed 😁 Nice

  • @mdsumonbbk8125
    @mdsumonbbk81253 жыл бұрын

    This is very helpfull for me.

  • @GuilhermeSilva-ex1qk
    @GuilhermeSilva-ex1qk3 жыл бұрын

    AWESOMEEEEE! VERY VERY GOOD BRO!

  • @eder.santana_oficial
    @eder.santana_oficial3 жыл бұрын

    Eu já entro dando like, seus vídeos são bons de mais

  • @stomperhk9107

    @stomperhk9107

    3 жыл бұрын

    KKKK, aposto que ele deve tá entendendo tudo

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

    How to creat a rotate effect icon on ckick?

  • @surenderoati
    @surenderoati3 жыл бұрын

    just awesome 🥰🥰

  • @IbrahimJalloh
    @IbrahimJalloh3 жыл бұрын

    Awesome, thanks...

  • @chemedev
    @chemedev3 жыл бұрын

    Impecable!

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

    Very nice Teacher

  • @tanishbhamare3365
    @tanishbhamare33653 жыл бұрын

    Awesome!👍👍

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

    Very nice!!!!

  • @Nehayadav-nh5zy
    @Nehayadav-nh5zy2 жыл бұрын

    Hey I am unable to see the active tab

  • @soft-coding
    @soft-coding3 жыл бұрын

    Thanks!!

  • @AJKING-tq3pd
    @AJKING-tq3pd3 жыл бұрын

    Sir please show how to make a calculater with the input from keyboard. I really worked hard but I didn't successed.

  • @htetwaiyan2499
    @htetwaiyan24993 жыл бұрын

    Very cool. Easy JS

  • @NejdetACAR
    @NejdetACAR3 жыл бұрын

    I think there's a logic error (in my opinion) in the code running After the content box is opened, it should only close when the content title is clicked, but it also closes when the content text is clicked. In other words, I want the opening and closing operations to be done only when the content title is clicked. I think this is what makes sense. How can I fix this problem.

  • @HongKong1842

    @HongKong1842

    3 жыл бұрын

    It actually becomes convenient when a reader clicks a larger area to close it. No need to be precise. Do you agree?

  • @beaq6755

    @beaq6755

    2 жыл бұрын

    @@HongKong1842 no, because I for example need the user to use inputs and buttons in the content part. How are they gonna use anything if as soon as they click the content disappears?

  • @brangja4815

    @brangja4815

    2 жыл бұрын

    You can achieve that like this. - Give the text tag a class name. - in eventListener function function(e) { if(e.target.closest("class_name_of_the_text_tag")) return; this.classList.toggle("active"); };

  • @kokonut5498

    @kokonut5498

    Жыл бұрын

    @@brangja4815 can you elaborate on this I tried what you said but it still doesnt work.

  • @donatocontinanza4331

    @donatocontinanza4331

    Жыл бұрын

    @@brangja4815 there is a better and easier solution.. by my opinion: const accordion = document.getElementsByClassName("content-box"); for(let i = 0; i accordion[i].firstElementChild.addEventListener("click", function() { accordion[i].classList.toggle("active"); }) } the firstElementChild will get the element (); obviously if you wounld insert other child elements first, you should change this property with children[nth] ...accordion[i].children[2].addEventListener("click", function() .... @kokonut5498

  • @Mieystery
    @Mieystery8 ай бұрын

    Can i make it already opened?

  • @anasyoussi514
    @anasyoussi5143 жыл бұрын

    Using ForEach : const accordion = document.querySelectorAll('.contentBx') ; accordion.forEach(acc => { acc.addEventListener('click', function(){ this.classList.toggle('active'); }) })

  • @muhammadluqmanhaqembinazwa1919

    @muhammadluqmanhaqembinazwa1919

    2 жыл бұрын

    WOOWWW THANK YOU SO MUCH!!!!!

  • @kaushalshinde2459

    @kaushalshinde2459

    2 жыл бұрын

    Y "this" keyword is used here? Can anybody explain plz...

  • @maskman4821
    @maskman48213 жыл бұрын

    This is vey useful, accordion seems play an important role in ui/ux, it is cool to have such an ui element in web page !!!

  • @AnujGupta-kw9sw
    @AnujGupta-kw9sw3 жыл бұрын

    Easiest than I've ever seen

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

    Good Video !

  • @gopalsaini4704
    @gopalsaini47042 жыл бұрын

    thanks a lot sir

  • @mr.guardian4491
    @mr.guardian44913 жыл бұрын

    Sir, how you learn these advanced things? Please tell me

  • @paulohrl13
    @paulohrl132 жыл бұрын

    Very niceee man s2s2s2 thank you very much

  • @michael_jordan_g
    @michael_jordan_g3 жыл бұрын

    amazing

  • @storytellersabanti
    @storytellersabanti3 жыл бұрын

    Can you create a tutorial -- when open a tab then automatically close the open tab

  • @BWVidventures
    @BWVidventures8 ай бұрын

    sir do u have a source code uploaded?

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

    hey!! my CSS are not reflecting??😮‍💨😮‍💨 help plsssss

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

    I want to close the first row if I clicked the second row. How can I do that?

  • @saidibrahim5931
    @saidibrahim59313 жыл бұрын

    Why toggle is not working for me, I did everything in this tutorial

  • @prasaddhend5500
    @prasaddhend55003 жыл бұрын

    Brother when we click on one box another box *automatically* closed. Like - when we click on 1st box 2,3,4 boxes close *automatically* When we click on 3rd box 1,2,4 boxes *automatically*.

  • @kareemreda5497

    @kareemreda5497

    2 жыл бұрын

    Use add and remove without toggle.

  • @renukagargicollege1486
    @renukagargicollege14863 жыл бұрын

    nice video

  • @roshansajeev4855
    @roshansajeev48553 жыл бұрын

    Hi onlinetut do you have a discord channel

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

    You should be using event delegation.

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

    thanks for this

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

    1:24 `body { display: flex; ` why?

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

    Nice

  • @twitchplus3593
    @twitchplus35933 жыл бұрын

    Awesome

  • @humaamwebdev6050
    @humaamwebdev60502 жыл бұрын

    mazaa agya

  • @tubaislam6527
    @tubaislam65272 жыл бұрын

    thanks

  • @shassan7
    @shassan79 ай бұрын

    height of conent should be changable due to text

  • @kkolenka
    @kkolenka2 жыл бұрын

    thanks. cool

  • @MuthuKumar-qx2ne
    @MuthuKumar-qx2ne2 жыл бұрын

    Super

  • @kumarianshu-zl6jo
    @kumarianshu-zl6jo Жыл бұрын

    heii my active is not working

  • @wtfmomentninenine
    @wtfmomentninenine3 жыл бұрын

    Iam from Indonesia 🇮🇩

  • @lefamofokeng8291
    @lefamofokeng82919 ай бұрын

    Source code??

  • @Bittu-hi4if
    @Bittu-hi4if3 жыл бұрын

    Bro can we make a app with html css and js

  • @kadircantoktas1117

    @kadircantoktas1117

    3 жыл бұрын

    Yes it is possible.

  • @robertoacuna4667
    @robertoacuna46672 жыл бұрын

    This is okay but if you click the body content it will be closed automatically, nice for viewing information but not in transactional HTML users

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

    send me code 🖥🖥 , Please 🙏🙏

  • @boyemarc-antoine7027
    @boyemarc-antoine70272 жыл бұрын

    if u dont put a fixed haight value, animation dont work.

  • @peshotod
    @peshotod3 жыл бұрын

    somehow the script doesn't work

  • @ahmadbinabaskpm-guru6532
    @ahmadbinabaskpm-guru6532 Жыл бұрын

    SIR CAN SHARE THE CODING

  • @thedev6368
    @thedev63683 жыл бұрын

    i fell asleep and its 6 oclock now

  • @ultimategaming517
    @ultimategaming5173 жыл бұрын

    you are legend buddy plez plez plez give me your no. i will not disturb you

  • @f.o.x.x.2.0
    @f.o.x.x.2.03 жыл бұрын

    else height content > 150px ?)

  • @mdmanik-xy7ui
    @mdmanik-xy7ui3 жыл бұрын

    I can make it bootstrap very easily

  • @HongKong1842

    @HongKong1842

    3 жыл бұрын

    What do you mean?

  • @Venistro
    @Venistro3 жыл бұрын

    Why with JavaScript and not CSS/HTML only?

  • @HongKong1842

    @HongKong1842

    3 жыл бұрын

    Would it become easier or harder? This version is quite simple enough to me already.

  • @Venistro

    @Venistro

    3 жыл бұрын

    @@HongKong1842 I would say simpler. But I would prefer CSS only, cause it still works when someone disable/blocks Javascript. Sometimes maybe because a self created adblocker filter blocks to much and such things.

  • @HongKong1842

    @HongKong1842

    3 жыл бұрын

    @@Venistro u mean js is simpler.

  • @Venistro

    @Venistro

    3 жыл бұрын

    @@HongKong1842 CSS only is simpler in my opinion. It uses only checkboxes and css selectors.

  • @HongKong1842

    @HongKong1842

    3 жыл бұрын

    @@Venistro perhaps you write and share a version for us to compare.

  • @cyrusgracias4556
    @cyrusgracias45563 жыл бұрын

    We can build accordion using HTML details and summary elements easily

  • @wisdomelue

    @wisdomelue

    3 жыл бұрын

    how do you add transitions to them, transitions seem not to take effect

  • @vietnguyenZ2
    @vietnguyenZ23 жыл бұрын

    It's nice but not dinamic. Because you fixed height when collapse. Scroll appear when content so long. I want more...

  • @OnlineTutorialsYT

    @OnlineTutorialsYT

    3 жыл бұрын

    Add Overflow-Y: auto; in .contntBx

  • @vietnguyenZ2

    @vietnguyenZ2

    3 жыл бұрын

    ​@@OnlineTutorialsYT I agree about scroll. But more case, content maybe short or long height, fixed height 150px is not perfect. Not same bootstrap collapse with all case

  • @youtubekunz
    @youtubekunz3 жыл бұрын

    i want to jojn

  • @ahmed-4065
    @ahmed-40652 жыл бұрын

    it doesn't work :(

  • @369vkr
    @369vkr3 жыл бұрын

    Hi where is da sos fil

  • @arminschneider9132
    @arminschneider91323 жыл бұрын

    What dont you know how to do?