A Pure Animated Accordion in CSS refers to a user interface (UI) design element that allows you to organize and present content in a collapsible and expandable manner using only Cascading Style Sheets (CSS), without relying on JavaScript or other scripting languages. An accordion typically consists of a series of panels or sections, and only one panel is expanded or visible at a time. When a user clicks on a panel's header or trigger, it expands to reveal its content, and if another panel is already open, it collapses.
The provided code is an HTML document that creates a simple Pure CSS Accordion. Let's break down the code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Pure CSS Accordion</title> <link rel="stylesheet" href="css/style.css" /> </head> <body> <div class="container"> <div> <input type="radio" id="ac1" name="accordion" checked /> <label for="ac1">Lorem ipsum dolor sit amet.</label> <div class="ac"> <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quam itaque officiis, ratione accusantium temporibus adipisci. Fugiat ab dolorem quasi delectus voluptatibus recusandae error corrupti velit, magni consectetur aut ipsam fuga.</p> </div> </div> <div> <input type="radio" id="ac2" name="accordion" checked /> <label for="ac2">Lorem ipsum dolor sit amet.</label> <div class="ac"> <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quam itaque officiis, ratione accusantium temporibus adipisci. Fugiat ab dolorem quasi delectus voluptatibus recusandae error corrupti velit, magni consectetur aut ipsam fuga.</p> </div> </div> <div> <input type="radio" id="ac3" name="accordion" checked /> <label for="ac3">Lorem ipsum dolor sit amet.</label> <div class="ac"> <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quam itaque officiis, ratione accusantium temporibus adipisci. Fugiat ab dolorem quasi delectus voluptatibus recusandae error corrupti velit, magni consectetur aut ipsam fuga.</p> </div> </div> <div> <input type="radio" id="ac4" name="accordion" checked /> <label for="ac4">Lorem ipsum dolor sit amet.</label> <div class="ac"> <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quam itaque officiis, ratione accusantium temporibus adipisci. Fugiat ab dolorem quasi delectus voluptatibus recusandae error corrupti velit, magni consectetur aut ipsam fuga.</p> </div> </div> </div> </body> </html>
This code implements a basic accordion using radio buttons and labels. However, there is a small mistake in the input elements. The checked attribute should be present only on one of the radio buttons to indicate the default open state. In the provided code, all radio buttons have checked, which may lead to unexpected behavior. Consider removing the checked attribute from all but one of the radio buttons.
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap"); * { margin: 0; padding: 0; box-sizing: border-box; font-family: "Poppins", sans-serif; } body { background-color: aliceblue; min-height: 100vh; display: grid; place-items: center; } .container { max-width: 600px; box-shadow: rgba(50, 50, 93, 0.25) 0px 2px 5px -1px, rgba(0, 0, 0, 0.3) 0px 1px 3px -1px; } .container input[type="radio"] { display: none; } .container label { cursor: pointer; height: 40px; line-height: 40px; display: block; background-color: #1b7f79; color: #fff; padding: 0px 10px; transition: background 0.5s; } .container input:checked + label, .container label:hover { background-color: #ff4858; } .ac { background: rgba(255, 255, 255, 0.5); overflow: hidden; color: #333; transition: height 0.3s ease-in-out; height: 0; } .ac p { color: #777; padding: 20px; font-weight: 400; } .container input:checked ~ .ac { height: 150px; }
Overall, this CSS code creates a visually appealing Pure CSS Accordion with a clean design and smooth transitions. The accordion allows users to click on the labels to expand and collapse the associated content.
This simple example demonstrates the core concept of a Pure Animated Accordion in CSS. Adjust the styles and animations to suit your design preferences and project requirements. The idea is to create a user-friendly and visually appealing way to organize and present content on a webpage.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions