AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

How to Create Accordion HTML Templates


<< Previous Page
HTML comment
Next Page >>
div class container

How to » How to Create Accordion HTML Templates

Study in this chapter:
1. - HTML CSS accordion exemple only
2. - Accordion without javascript
3. - Simple pure css accordion

Learn how to create an accordion (collapsible content).

We can add CSS style to accordion as:
Internal Style - by using a <style> element in the <head> section
External Style - by using an external CSS file as style.css

Example:

 

HTML / CSS only responsive accordion

Example of HTML / CSS only responsive accordion

Example:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">

<style>
body {
font-family: Georgia, "Times New Roman", Times, serif;
margin-top: 8px;
margin-right: 12px;
margin-bottom: 8px;
margin-left: 12px;
}
.header {
height: 40px;
width: 100%;
margin-right: auto;
margin-left: auto;
padding-top: 12px;
padding-bottom: 12px;
font-size: 36px;
font-weight: bold;
background-color: #EFEFEF;
}
.link {
font-size: 18px;
font-weight: bold;
line-height: 28px;
color: #004E9B;
text-decoration: none;
}
/*Acco*/
.ac-container {
max-width: 300px;
float: left;
}

.ac-container label {
height: 30px !important;
line-height: 21px !important;
font-size: 12px !important;
font-family: 'Open Sans','Arial Narrow',Arial,sans-serif !important;
padding: 5px 20px;
position: relative;
z-index: 20;
display: block;
height: 30px;
cursor: pointer;
color: #777;
text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
line-height: 33px;
font-size: 19px;
background: #fff;
background: -moz-linear-gradient(top,#fff 1%,#eaeaea 100%);
background: -webkit-gradient(linear,left top,left bottom,color-stop(1%,#fff),color-stop(100%,#eaeaea));
background: -webkit-linear-gradient(top,#fff 1%,#eaeaea 100%);
background: -o-linear-gradient(top,#fff 1%,#eaeaea 100%);
background: -ms-linear-gradient(top,#fff 1%,#eaeaea 100%);
background: linear-gradient(top,#fff 1%,#eaeaea 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fff',endColorstr='#eaeaea',GradientType=0 );
box-shadow: 0 0 0 1px rgba(155,155,155,0.3),1px 0 0 rgba(255,255,255,0.9) inset,0 2px 2px rgba(0,0,0,0.1);
font-size: 12px;
height: 30px;
line-height: 20px;
}

.ac-container {
width: 100%;
margin: 10px auto 30px auto;
text-align: left;
}

.ac-container label:hover {
background: #fff;
}

.ac-container input:checked + label,.ac-container input:checked + label:hover {
background: #f1f2f3;
color: #666;
text-shadow: 0 1px 1px rgba(255,255,255,0.6);
box-shadow: 0 0 0 1px rgba(155,155,155,0.3),0 2px 2px rgba(0,0,0,0.1);
height: 30px;
line-height: 21px;
font-size: 13px;
}

.ac-container label:hover:after,.ac-container input:checked + label:hover:after {
content: '';
position: absolute;
width: 24px;
height: 24px;
right: 13px;
top: 7px;
background: transparent url(../images/arrow_down.png) no-repeat center center;
}

.ac-container input:checked + label:hover:after {
background-image: url(../images/arrow_up.png);
}

.ac-container input {
display: none;
}

.ac-container article {
background: rgba(255,255,255,0.5);
margin-top: -1px;
overflow: hidden;
height: 0;
position: relative;
z-index: 10;
-webkit-transition: height 0.3s ease-in-out,box-shadow 0.6s linear;
-moz-transition: height 0.3s ease-in-out,box-shadow 0.6s linear;
-o-transition: height 0.3s ease-in-out,box-shadow 0.6s linear;
-ms-transition: height 0.3s ease-in-out,box-shadow 0.6s linear;
transition: height 0.3s ease-in-out,box-shadow 0.6s linear;
}

.ac-container article p {
font-style: normal;
color: #777;
line-height: 23px;
font-size: 10px;
padding: 20px;
text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
font: normal normal 12px 'Open Sans';
}

.ac-container input:checked ~ article {
-webkit-transition: height 0.5s ease-in-out,box-shadow 0.1s linear;
-moz-transition: height 0.5s ease-in-out,box-shadow 0.1s linear;
-o-transition: height 0.5s ease-in-out,box-shadow 0.1s linear;
-ms-transition: height 0.5s ease-in-out,box-shadow 0.1s linear;
transition: height 0.5s ease-in-out,box-shadow 0.1s linear;
box-shadow: 0 0 0 1px rgba(155,155,155,0.3);
}

.ac-container input:checked ~ article.ac-small {
height: 140px;
}

.ac-container input:checked ~ article.ac-medium {
height: 180px;
}

.ac-container input:checked ~ article.ac-large {
height: 230px;
}
</style>
</head>
<body>
<!--
<div class="header">Logo_website</div>
<br />
-->
<section class="ac-container">
<div>
<input id="ac-1" name="accordion-1" type="radio" checked="">
<label for="ac-1">About us</label>
<article class="ac-small">
<p>
<a class="link" href="#">Link 1</a><br />
<a class="link" href="#">Link 2</a><br />
<a class="link" href="#">Link 3</a></p>
</article>
</div>
<div>
<input id="ac-2" name="accordion-1" type="radio">
<label for="ac-2">How we work</label>
<article class="ac-medium">
<p>Like you, I used to think the world was this great place where
everybody lived by the same standards I did, then some kid with a nail
showed me I was living in his world, a world where chaos rules not order,
a world where righteousness is not rewarded. </p>
</article>
</div>
<div>
<input id="ac-3" name="accordion-1" type="radio">
<label for="ac-3">References</label>
<article class="ac-large">
<p>You think water moves fast? You should see ice. It moves like
it has a mind. Like it knows it killed the world once and got a taste
for murder. After the avalanche, it took us a week to climb out. Now,
I don't know exactly when we turned on each other, but I know that seven
of us survived the slide... and only five made it out. a candle to man. </p>
</article>
</div>
<div>
<input id="ac-4" name="accordion-1" type="radio">
<label for="ac-4">Contact us</label>
<article class="ac-large">
<p>You see? It's curious. Ted did figure it out - time travel. And when we get back, we gonna tell everyone. How it's possible, how it's done, what the dangers are. But then why fifty years in the future when the spacecraft encounters a black hole does the computer call it an 'unknown entry event'? </p>
</article>
</div>
</section>

</body>
</html>

Related subjects:
Sidebar navigation with scroll bar How to Create a Sticky Navbar Top navigation bar HTML CSS

 

Accordion with symbols using javascript

In this example we have added a "plus" sign to each button. When the user clicks on the button, the "plus" sign is replaced with a "minus" sign.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
transition: 0.4s;
}

.active, .accordion:hover {
background-color: #ccc;
}

.accordion:after {
content: '\002B';
color: #777;
font-weight: bold;
float: right;
margin-left: 5px;
}

.active:after {
content: "\2212";
}

.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
</style>
</head>
<body>

<h2>Accordion with symbols</h2>
<p>In this example we have added a "plus" sign to each button.
When the user clicks on the button, the "plus"
sign is replaced with a "minus" sign.</p>
<button class="accordion">Section 1</button>
<div class="panel">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>

<button class="accordion">Section 2</button>
<div class="panel">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>

<button class="accordion">Section 3</button>
<div class="panel">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>

<script>
var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
}
</script>

</body>
</html>

 

Tags: styles, design, template, html css accordion exemple only, html css accordion without javascript, simple pure css accordion

 

Simple pure CSS accordion template

Example - How to create a Simple pure CSS accordion template?

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accordion 2.0</title>
<style>
body {
color: rgba(4,57,94,1);
background: rgba(4,57,94,.1);
padding: 0 1em 1em;
font-family: 'Open Sans', sans-serif;
}
h1{
text-align:center;
}
input {
position: absolute;
opacity: 0;
z-index: -1;
}
.accordion-wrapper {
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 4px -2px rgba(0, 0, 0, 0.5);
width: 600px;
margin:0 auto;
}
.accordion {
width: 100%;
color: white;
overflow: hidden;
margin-bottom: 16px;
}
.accordion:last-child{
margin-bottom: 0;
}
.accordion-label {
display: flex;
-webkit-box-pack: justify;
justify-content: space-between;
padding: 16px;
background: rgba(4,57,94,.8);
font-weight: bold;
cursor: pointer;
font-size: 20px;
}
.accordion-label:hover {
background: rgba(4,57,94,1);
}
.accordion-label::after {
content: "\276F";
width: 16px;
height: 16px;
text-align: center;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.accordion-content {
max-height: 0;
padding: 0 16px;
color: rgba(4,57,94,1);
background: white;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.accordion-content p{
margin: 0;
color: rgba(4,57,94,.7);
font-size: 18px;
}
input:checked + .accordion-label {
background: rgba(4,57,94,1);
}
input:checked + .accordion-label::after {
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
input:checked ~ .accordion-content {
max-height: 100vh;
padding: 16px;
}

</style>
</head>
<body>
<h1>How to create an accordion without using javascript</h1>
<div class="accordion-wrapper">
<div class="accordion">
<input type="radio" name="radio-a" id="check1" checked>
<label class="accordion-label" for="check1">Accordion 1</label>
<div class="accordion-content">
<p>Hey there, you are watching codiesbugs &#128522;</p>
</div>
</div>
<div class="accordion">
<input type="radio" name="radio-a" id="check2">
<label class="accordion-label" for="check2">Accordion 2</label>
<div class="accordion-content">
<p>I hope you are enjoing the video, don't forget to give your feedback in comment section</p>
</div>
</div>
<div class="accordion">
<input type="radio" name="radio-a" id="check3">
<label class="accordion-label" for="check3">Accordion 3</label>
<div class="accordion-content">
<p>If you liked then don't forget to subscribe the channel for latest videos. </p>
</div>
</div>
</div>
</body>
</html>

 

Summary of description

 

<< Previous Page
HTML Button Style
Next Page >>
HTML Button Action

 



styles, design, template, html css accordion exemple only, html css accordion without javascript, simple pure css accordion
How to Create Accordion HTML Templates - how to

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Upload Image, display, edit and delete i...
Login Form with Image background...
How to Create an Image with Transparent ...
Portfolio Gallery Website with filtering...
Simple pagination script PHP MySQLi...
Center Image in div...
Image Hover Overlay Fade...
Sticky image / element / div on scroll...
Responsive images...
Create rounded image in HTML CSS...
Add border around image...
Position Text Over an Image HTML CSS res...
Create a Slideshow Images Gallery...
Create a Sticky Sidebar...
Search bar using CSS HTML...
Shrink Navigation Menu on Scroll...
How to Create Accordion HTML Templates...
Dropdown menu in the navigation bar...
Responsive Top Navigation Bar with mobil...
Split horizontal navigation bar...