{"id":29456,"date":"2015-11-04T06:07:09","date_gmt":"2015-11-04T00:37:09","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=29456"},"modified":"2017-09-12T12:45:21","modified_gmt":"2017-09-12T07:15:21","slug":"create-accordion-with-css-and-html-without-js","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/create-accordion-with-css-and-html-without-js\/","title":{"rendered":"Create Accordion with CSS and HTML without JS"},"content":{"rendered":"<p>There are many way to create the accordion effect with js but following are the example of how to create the accordion only with css and html.<\/p>\n<h3>Here is the image that show which type of accordion I am going to create.<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-29458\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/11\/accordion.jpg\" alt=\"accordion\" width=\"300\" height=\"334\" \/><\/p>\n<h3>Now starts with html code:<\/h3>\n<p>In this I have used checkbox to use the functionality of click. But we will not display these input checkboxes. We can use display none to hide the checkbox. Also I am using label for tab1 and tab2 design.<\/p>\n<h3>HTML CODE:<\/h3>\n<p>[java]&lt;div id=&quot;nestle-section&quot;&gt;<br \/>\n\t&lt;input type=&quot;radio&quot; id=&quot;tab1&quot; name=&quot;tabs&quot; checked=&quot;&quot;\/&gt;<br \/>\n\t&lt;label for=&quot;tab1&quot;&gt;Tab1&lt;\/label&gt;<br \/>\n\t&lt;div class=&quot;tab-content1&quot;&gt;<br \/>\n\t\tLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#8217;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It<br \/>\n\t&lt;\/div&gt;<\/p>\n<p>\t&lt;input type=&quot;radio&quot; id=&quot;tab2&quot; name=&quot;tabs&quot;\/&gt;<br \/>\n\t&lt;label for=&quot;tab2&quot;&gt;Tab2&lt;\/label&gt;<br \/>\n\t&lt;div class=&quot;tab-content1&quot;&gt;<br \/>\n\t\tLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#8217;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It<br \/>\n\t&lt;\/div&gt;<br \/>\n&lt;\/div&gt;[\/java]<\/p>\n<h3>Css Code:<\/h3>\n<p>Styling of Tab1 and Tab2 label:<\/p>\n<p>[java]#nestle-section{<br \/>\n\tfloat:left;<br \/>\n\twidth:300px;<br \/>\n\tposition:relative;<br \/>\n}<br \/>\n#nestle-section label{<br \/>\n\tfloat:left;<br \/>\n\twidth:100%;<br \/>\n\tbackground:#333;<br \/>\n\tcolor:#fff;<br \/>\n\tpadding:5px 0;<br \/>\n\ttext-align:center;<br \/>\n\tcursor:pointer;<br \/>\n\tborder-bottom:1px solid #fff;<br \/>\n}[\/java]<\/p>\n<p>Styling of accordion content:<\/p>\n<p>[java]#nestle-section .tab-content1{<br \/>\n\tfloat:left;<br \/>\n\twidth:280px;<br \/>\n\tpadding:0 10px;<br \/>\n\theight:0;<br \/>\n\t-moz-transition: height 1s ease;<br \/>\n\t-webkit-transition: height 1s ease;<br \/>\n\t-o-transition: height 1s ease;<br \/>\n\ttransition: height 1s ease;<br \/>\n\toverflow:hidden;<br \/>\n}[\/java]<\/p>\n<p>Then I give the following style for accordion animation onclick of Tab1 and Tab2 labels:<\/p>\n<p>[java]#nestle-section  input:checked + label + .tab-content1{<br \/>\n\tpadding: 10px;<br \/>\n\theight: 150px;<br \/>\n\t-moz-transition: height 1s ease;<br \/>\n\t-webkit-transition: height 1s ease;<br \/>\n\t-o-transition: height 1s ease;<br \/>\n\ttransition: height 1s ease;<br \/>\n}<br \/>\n#nestle-section input:checked + label{<br \/>\n\tbackground:#ccc;<br \/>\n\tcolor:#333;<br \/>\n}[\/java]<\/p>\n<p>Then we hide the radio:<\/p>\n<p>[java]#nestle-section input{<br \/>\n\tdisplay:none;<br \/>\n}[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many way to create the accordion effect with js but following are the example of how to create the accordion only with css and html. Here is the image that show which type of accordion I am going to create. Now starts with html code: In this I have used checkbox to use [&hellip;]<\/p>\n","protected":false},"author":206,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2},"categories":[3429,1],"tags":[2965,2966,2967,355,4842],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/29456"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/206"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=29456"}],"version-history":[{"count":2,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/29456\/revisions"}],"predecessor-version":[{"id":51801,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/29456\/revisions\/51801"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=29456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=29456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=29456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}