How to Create an Accordion with Vanilla JavaScript

preview_player
Показать описание

====================

I'm back at it with my Let's Build: With JavaScript series. This week I take a stab at creating a custom accordion component with vanilla JavaScript.

An accordion is a useful component for dealing with a lot of extra content that doesn't necessarily always need to display. You might use an accordion to call out specific features of an application, show and hide content that isn't always important but is indeed useful to your given web design. I have even seen an entire F.A.Q. section built successfuly with accordions.

Much like the instrument an accordion shows and had panels when a given panel is active. In this video tutorial I'll teach you a vanilla JavaScript way of creating a simple accordion. Since we are spending some time crafting the interactions with JavaScript, I also wanted to make the accordion look good as well.

For this I reach for Tailwind CSS. Tailwind is a utility-driven CSS framework, useful for coding designs in a more scalable and resusable fashion. Sure, you can use custom styles or other frameworks just the same but they are rather opinionated approaches in some cases.

====================

💻 Previously published at:

💻 Check out the blog:

🦄 Check out my personal site:

🚀 Links:

📘Check out my book on UX Design:
"LUXD: Learn User Experience Design"

📙 Check out my FREE book on Tumblr Theming:
"Pro Tumblr Theming"

💯 Need awesome web hosting? Check out cloudways. They allow me to use a variety of hosting providers and build apps with ease:

🌊 Need more advanced hosting for Rails, PHP, Node, or other projects? Digital Ocean has you covered.

☕️ 🙏🏻 Patreon

☕️ Or buy me a coffee
Рекомендации по теме
Комментарии
Автор

You are supposed to be having alot of subscribers by this channel of yours.

unchart_d
Автор

very coll thanx a mill. one thing though, I'm to using the tailwind but rather styled it myself. All looks good and works well except for when i click the title the content does not open downwards but kinda "jumps" opening from the center I guess. how to I fix this?

GavinWoodthebarbarian
Автор

Another awesome video, man!! Really appreciate it! I love your channel, it's full of amazing content. Thanks Andy!

alegamerograu
Автор

You deserve more subscribers! Keep rockin'

filippobarcellos
Автор

First of all I really like this tutorial but I tried it without Tailwind CSS and couldn't make it work. I have the first pane open, but when I click any of the others title rows it closes the first one and doesn't open any. Do you have any idea why this is happening? Could you maybe have a codepen of this accordion without Tailwind just so that I can check it? Thanks.

sergiof.
join shbcf.ru