How to Create Switchable Tabs - HTML, CSS & JavaScript Tutorial

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • In this video we'll be looking at creating tabbed sections from scratch using pure HTML, CSS and JavaScript - it's super easy to do and doesn't require that much work.
    Note that this doesn't require any sort of library such as jQuery or any other front-end JavaScript framework.
    Support me on Patreon:
    / dcode - with enough funding I plan to develop a website of some sort with a new developer experience!
    Follow me on Twitter @dcode!
    If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
    #dcode #webdev #javascript

КОМЕНТАРІ • 79

  • @vaishalitiwari8020
    @vaishalitiwari8020 4 роки тому +4

    This was the only video that actually taught how to form tabs AND display the contents of each tab only on click... and hallelujah! it actually works! Thank you soooo much for this video...you are a lifesaver. I would have been on the wrong side of my teacher had you not uploaded this video. Keep uploading more awesome videos and helping students like me : )

  • @alimansourey2076
    @alimansourey2076 3 роки тому +2

    The idea is simple. The html and css parts are straightforward , The problem is in class naming ... he used the word tab everywhere .. It woould easier if he used something like : Tab , content , data--this-tab-for-content-number="1" . Also I think the document loading event is not necessary . This guy is highly skilled .

  • @maryAguti
    @maryAguti 4 роки тому +2

    Great video! Really easy to follow along. I had the same issues as everyone else with the null and that back tick is what got me.

  • @rkinsas2876
    @rkinsas2876 2 роки тому +12

    const tabToActivate = tabsContainer.querySelector(`.tabs__content[data-tab="${tabNumber}"]`);
    May be useful to someone..

  • @TekkenRoom
    @TekkenRoom 2 роки тому +1

    can't imagine how grateful i am for this tutorial , thank you sir

  • @pcslowhand
    @pcslowhand 4 роки тому +2

    Thanks for the tutorial. I had problems with the "button.classList.add" and "tabToActivate.classList.add" lines of code towards the end. I ended up using "button.classList = "tabs__button tabs__button--active" for it to work but I don't kow why your code wasn't running. Thanks again.

    • @JayCeee509
      @JayCeee509 2 роки тому

      I think may have same problem as you. so what did you change in the code?

  • @1_PieceOfCode
    @1_PieceOfCode 2 роки тому +1

    love the tutorial it was very helpful. thanks man you get a sub today 👍

  • @francois1e4
    @francois1e4 5 років тому +2

    Thanks for mentioning BEM. didn't know that was a thing :)

    • @dcode-software
      @dcode-software  5 років тому

      Haha you're welcome, mate it's good - I always use it for all my projects

  • @anne4381
    @anne4381 2 роки тому

    Awesome! You got a new subscriber :)

  • @bikramchettri9405
    @bikramchettri9405 5 років тому +2

    Good one mate.

  • @sallahbaboucarr368
    @sallahbaboucarr368 3 роки тому

    Thanks so much, this video was a lifesaver

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

    Thank you

  • @liviumitrofan
    @liviumitrofan 3 роки тому

    Super video!! What vs code theme do you use?

  • @luc4y1
    @luc4y1 3 роки тому

    This is AWESOME! Thank you so much!

  • @mattk4323
    @mattk4323 5 років тому +1

    great video mate

  • @channelone1191
    @channelone1191 5 років тому +1

    Hey! Nice vid, whats the font in vs code? Looks pretty good

  •  3 роки тому

    thank youu, I should try it immediately!

  • @elifas2012
    @elifas2012 4 роки тому

    Thanks, that was pretty useful information

  • @ihorvoznyi1506
    @ihorvoznyi1506 2 роки тому

    Love u dude

  • @anishk.4813
    @anishk.4813 4 роки тому +1

    On the CSS part, only one of my sections are dissipearing, and not all of them. I did exactly what you did though

  • @miguelquintero5937
    @miguelquintero5937 3 роки тому

    The video is very good, I just think you should have left
    the code in the description so you don't have to write everything by hand jaja

  • @joshcollins9125
    @joshcollins9125 3 роки тому

    I've gone through everything in the video and have it working but the buttons aren't working properly. The active button changes colour after becoming active, only after I click the button and then click elsewhere. It's like this for both Edge and Chrome at least. Any ideas why?

  • @CharlieIsThere
    @CharlieIsThere 2 роки тому

    What theme and font do you use for VS code editor? It looks elegant.

  • @1_PieceOfCode
    @1_PieceOfCode 2 роки тому

    1:15 if the css file is empty then why there is styling on the h1 tag??

  • @Rita-og7cy
    @Rita-og7cy 2 роки тому

    Thanks

  • @plickgaming4035
    @plickgaming4035 4 роки тому

    css end timestamps: 10:18

  • @yousseflahmadi7665
    @yousseflahmadi7665 2 роки тому

    I really liked the video thank you .I have a little error tabscontainer in tabToAtctivate is indefined but i sure i a did the correct classe do you have anyidea why ? Thank you in adavance .

  • @MaxProgramming
    @MaxProgramming 4 роки тому

    Which theme are you using in vscode?

  • @qasimnawab957
    @qasimnawab957 3 роки тому

    love it.

  • @malazma2435
    @malazma2435 3 роки тому

    Is it possible to activate the last selected tab, i mean if we save last tabNumber and activate it while reloading the page.

  • @miruku7648
    @miruku7648 4 роки тому

    Is there any easy way to add a transition effect to this?

  • @paulmoldovan9518
    @paulmoldovan9518 4 роки тому

    How can i submit a form inTab #2 and stay in Tab #2 after form is submited?

  • @keshavgoyal568
    @keshavgoyal568 3 роки тому

    How can I implement an add tab or new tab button?

  • @chipsmaster320
    @chipsmaster320 2 роки тому

    what's that font its awesome?

  • @jdeso3
    @jdeso3 4 роки тому +4

    I love the idea of this but I can't make it work I've been proofing it for two days I found a couple of mistakes but they didn't fix it it doesn't work when I click on the tab I don't get any little green bar or bold text and I don't see the content I sure wish you'd post this codes that somebody could just download it.

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

    Great video but for some reason this line does not work for me....tabToActivate.classList.add("tabs__content--active"); I get the following error message
    :110 Uncaught TypeError: Cannot read properties of null (reading 'classList')
    at HTMLButtonElement.
    Does anyone know how to fix this?

  • @Coder-Journey
    @Coder-Journey 2 роки тому

    how to make them auto switching

  • @Learn9Passion
    @Learn9Passion 3 роки тому

    I need support for one activity, will you provide ?

  • @nicoap4315
    @nicoap4315 4 роки тому

    can we replace "click" to "hover over" for change the tab?

    • @quangkhuat5365
      @quangkhuat5365 4 роки тому

      There is an event call "mouseover". U can try it out

  • @piknujena3380
    @piknujena3380 5 років тому

    hi, my css3 and html is workout but javascript code is not working, pls help me?

    • @wahyusaragih4265
      @wahyusaragih4265 5 років тому

      this question is broad. You can check the bem class name

  • @LexiumHub
    @LexiumHub 3 роки тому

    mine isnt working bro could you share a github link ?

  • @peshawaamin3083
    @peshawaamin3083 2 роки тому

    ❤️❤️

  • @tranhuyhung157
    @tranhuyhung157 4 роки тому

    Can you create nested tabs with HTML, CSS and Js :D
    Thank you

  • @joehenrickson
    @joehenrickson 3 роки тому

    Everything works but the content. I'm having an error that states, "Cannot read property ' classList' of NULL. I see someone in the comments found their way around this but I don't know how they did it. Hopefully you are still able to respond to these comments. I appreciate your help and the training. It's very helpful. tabs__content has everything gone if I add tabs__content--active it appears but not on click.

    • @dcode-software
      @dcode-software  3 роки тому

      Hey Joe, check the spelling in your query selector or get element by ID. Otherwise, if your script is in your head tag, move to the end of body.

    • @joehenrickson
      @joehenrickson 3 роки тому

      @@dcode-software I actually ended up getting it to work. I don't remember how, but it's working. I believe I had an extra div tag somewhere. Thank you so much for your help.

  • @emreunlu7776
    @emreunlu7776 3 роки тому

    what's your using font ?

  • @zoltek3638
    @zoltek3638 4 роки тому

    the same but without attributes:
    let tabsItem = document.querySelectorAll('.tabs-button');
    let tabsBlock = document.querySelectorAll('.tabs-block');
    for (let i = 0; i < tabsItem.length; i++) {
    tabsItem[i].addEventListener('click', function () {
    tabsItem.forEach(button => {
    button.classList.remove('active');
    });
    tabsBlock.forEach(button => {
    button.classList.remove('active');
    });
    tabsItem[i].classList.add('active');
    tabsBlock[i].classList.add('active');
    });
    }

  • @fracturedude
    @fracturedude 4 роки тому

    can you upload the code to github?

  • @giovannimichel5506
    @giovannimichel5506 2 роки тому

    Can you please provide the source codes?

  • @arbazwassan1285
    @arbazwassan1285 2 роки тому

    Source code please

  • @christopherabela9299
    @christopherabela9299 4 роки тому

    when using this combined with a form, the page keeps reloading, anyone encountered such an issue?

    • @dcode-software
      @dcode-software  4 роки тому

      Make sure you have your "type" attribute set to "button"

    • @christopherabela4835
      @christopherabela4835 3 роки тому

      @@dcode-software got it, thanks a lot for the assistance!

  • @vairamvairamuthu8954
    @vairamvairamuthu8954 3 роки тому

    My button can't click and change☹️

  • @yousseflahmadi7665
    @yousseflahmadi7665 2 роки тому

    I just saw this vedio is 3 years old hope i get an answer

  • @Learn9Passion
    @Learn9Passion 3 роки тому

    HI

  • @slowcodersloth
    @slowcodersloth 2 роки тому

    No one use "master" for css.

  • @TheEXmasterwrecker
    @TheEXmasterwrecker 3 роки тому

    whelp... i followed the tutorial as best as i could... and it still doesnt work... got damnit i miss my teacher... he died from covid while i was working on this...

  • @snouzz-gaming
    @snouzz-gaming Рік тому

    dont work with django ...