How to create Hidden Header using Google AMP amp-accordion?

Introduction: Sometimes we have a lot of content to display and to make the website look pretty and short we make use of the collapsible textboxes. Collapsible textboxes are that division which is the combination of heading and content, generally only heading is visible but when it is hit the content is displayed.

Setup:

  • You have to import amp-accordion component in your header to use this tag.




<script async custom-element="amp-accordion"
       src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js">
</script>


  • To achieve Hidden Header style use the code mention below:




<amp-accordion class="sample hidden-header"
  disable-session-states>
  <!-- Content -->
</amp-accordion>


Example:




<!doctype html>
<html <img draggable="false" 
     class="emoji" alt="" 
     src=
"https://s.w.org/images/core/emoji/11/svg/26a1.svg">
<head>
  <meta charset="utf-8">
  <title>w3wiki | amp-accordion</title>
  <script async src=
     "https://cdn.ampproject.org/v0.js">
  </script>
  <!--
 Import the `amp-accordion` component in the header.
  -->
  <script async custom-element="amp-accordion" 
          src=
"https://cdn.ampproject.org/v0/amp-accordion-0.1.js">
  </script>
  <link rel="canonical" href=
"https://amp.dev/documentation/examples/components/amp-accordion/index.html">
  <meta name="viewport" 
        content="width=device-width, 
                 minimum-scale=1
                 initial-scale=1">
  <style amp-boilerplate>
  body {
    -webkit-animation:-amp-start 8s steps(1, end) 0s 1 normal both;
    -moz-animation:-amp-start 8s steps(1, end) 0s 1 normal both;
    -ms-animation:-amp-start 8s steps(1, end) 0s 1 normal both;
    animation:-amp-start 8s steps(1, end) 0s 1 normal both
  }
  @-webkit-keyframes -amp-start{
    from{
      visibility:hidden
    }
    to{
      visibility:visible
    }
  }@-moz-keyframes -amp-start{
    from{
      visibility:hidden
    }
    to{
      visibility:visible
    }
  }
  @-ms-keyframes -amp-start{
    from{
      visibility:hidden
    }
    to{
      visibility:visible
    }
  }
  @-o-keyframes -amp-start{
    from{
      visibility:hidden
    }
    to{
      visibility:visible
    }
  }
  @keyframes -amp-start{
    from{
      visibility:hidden
    }
    to{
      visibility:visible
    }
  }
</style>
<noscript>
  <style amp-boilerplate>
    body{
      -webkit-animation:none;
      -moz-animation:none;
      -ms-animation:none;
      animation:none
    }
  </style>
</noscript>
  <style amp-custom>
    amp-accordion section[expanded] .show-more {
      display: none;
    }
  
    amp-accordion.hidden-header section[expanded] h4 {
      border: none;
    }
  
    /* these styles are not required for the samples to work */
    :root {
      --space-2: 1rem;
      /* 16px */
    }
  
    amp-accordion.sample {
      margin: var(--space-2);
    }
  
    h1, h4{
      color: forestgreen;
    }
    section {
      color: crimson;
    }
</style>
<meta name="robots" content="noindex, nofollow">
</head>
<body>
  <center><h1>
    Beginner For Beginner
  </h1></center>
  <amp-accordion class="sample hidden-header"
    disable-session-states>
    <section>
      <h4><span class="show-more">Click it Geek!!</span></h4>
      <p>w3wiki is a Computer Science portal for Beginner. 
It contains well written, well thought and well explained 
computer science and programming articles, quizzes etc.</p>
    </section>
  </amp-accordion>
</body>
</html>


Output: