Simple Accordion Design using only HTML and CSS

Simple Accordion Design using only HTML and CSS

Those of you who are learning new web design should know accordion and how it works by now. An accordion is a vertically stacked list of titles, and when we click on the Heading or title, it reveals or hides the text content or other elements associated with it. All Modern website has got at least one accordion, and they mostly use it for FAQ section, Specification section, etc.

In this program, we will design a simple-looking accordion with HTML and CSS. I have not used any jquery or javascript for the functionality of the accordion. The accordion title is some dummy text like Accordion one, two, and three. Then in the collapsible items, I also used some dummy text of lorem ipsum. You can put other types of content here like an image, ordered list, unordered list, etc. in there. But for the sake of this tutorial, I used plain text. So whenever we click on the Heading or title, the dummy text or the content associated with it will reveal and hide.



In the HTML markup, I have taken a div element with a ''container' class, which will contain the accordion elements. After that, I have taken three div elements with the class name of accordion. I then have taken a label named accoedion1. I provided an h2 tag with the text ''the first accordion". Then I have taken an input element of the checkbox with an id of the same name used for the label underneath the input element. I have to take a paragraph tag with a class name of a single-text. I provided some random text inside the p tag. for the other two accordion class div, I have changed the label name, text inside a p tag, and the id name.
You may also like:
In the CSS part,  we need to discard the document's default padding and the margin. Therefore we set the padding and margin to 0. we then set pleasant gradient background color for the body tag. Then I have provided a 100vh height to the body. We will give the container id a width and height of 700px and auto, respectively.  Then we set the margin to 0 auto so that the container comes in the middle of the document. After that, we will give the label a style by providing it a background color, padding, alignment, margin, and other necessary styles. We set the label to display block so that it occupies the whole width of the container. We then style the text inside the label tag. After will make some styling for the text content inside the single-text class, at the initial stage, the visibility will be hidden, and the opacity will be 0, and the display will be none. But when the label is clicked or checked, the display will be blocked, visibility will be visible, and opacity will be one. For each label, we have to set the display to none and position to a relative as well.
For the implementation of this snippet, we need to create two separate files of HTML and CSS, and after the creation of these files, you have to link the CSS file to your HTML file. Then copy the code below and paste the codes in the respective file and run index.html file in the browser.

HTML:




CSS:




I hope you liked the snippet. Please feel free to leave a comment down below. I will try to answer them as soon as I can. Thanks for visiting the blog.

1 Comments

Please do not enter any spam link in the comment box.

Post a comment

Please do not enter any spam link in the comment box.

Post a Comment

Previous Post Next Post