Creating a Simple Vertical Infographic Timeline using HTML and CSS Tutorial

In this tutorial, you will learn to create a Simple Vertical Infographic Timeline for your site using HTML and Pure CSS. The tutorial aims to provide the students, self-learners, and new programmers with a reference to guide them in creating their own timeline design using only CSS. Here, snippets and source code scripts for creating a vertical timeline are provided. The complete source code zip file is also provided and is free to download.

What is Infographic Timeline?

The Infographic Timeline is a visually represented information in the context of time progression. It is a highly common structure, particularly in presentations. It is used to list information to draw attention to certain facts by connecting them to a specific period of time while fulfilling the need for the facts to be described in detail.

How to create a Vertical Infographic Timeline using HTML and CSS?

We can create a Vertical Infographic Timeline using HTML and CSS. Here are the following HTML elements and CSS pseudo-element that are useful in creating the Timeline design.

  • HTML Details <details></details> Element
  • HTML Summary <summary></summary> Element
  • HTML Unordered List <ul></ul> Element
  • HTML List Item <li></li> Element
  • CSS ::before pseudo-element
  • CSS ::after pseudo-element

Using these HTML and CSS elements/pseudo-elements, we can create the design for timeline items containers, vertical lines, custom bullets, and more.

Example

Here are the snippets and scripts that demonstrate the creation of a simple vertical timeline.

Interface

The below script is an HTML file script that contains the timeline page interface elements. The script will output the page with a top navigation bar, footer, and timeline items.

index.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3.     <meta charset="UTF-8">
  4.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>CSS - Timeline</title>
  7.     <link rel="preconnect" href="https://fonts.googleapis.com">
  8.     <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  9.     <link href="https://fonts.googleapis.com/css2?family=Amatic+SC:wght@700&display=swap" rel="stylesheet">
  10.     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
  11.     <link rel="stylesheet" href="assets/css/styles.css">
  12.     <script src="https://code.jquery.com/jquery-3.6.1.js" integrity="sha256-3zlB5s2uwoUzrXK3BT7AX3FyvojsraNFxCc2vC/7pNI=" crossorigin="anonymous"></script>
  13.     <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
  14. </head>
  15.     <main>
  16.         <nav class="navbar navbar-expand-lg navbar-dark bg-gradient bg-dark">
  17.             <div class="container">
  18.                 <a class="navbar-brand" href="./">CSS - Timeline</a>
  19.                 <a href="https://sourcecodester.com" class="text-light fw-bolder h6 text-decoration-none" target="_blank">SourceCodester</a>
  20.             </div>
  21.         </nav>
  22.         <div id="main-wrapper" class="py-5 px-3">
  23.             <div class="container-fluid-md">
  24.                 <h1 class="text-center"><b>My Sample Timeline Data</b></h1>
  25.                 <hr class="border-3 border-dark mx-auto opacity-100" style="width:80px">
  26.                 <div id="timeline-container" class="mt-4">
  27.                     <ul id="timeline-list">
  28.                         <li>
  29.                             <div class="timeline-item-container">
  30.                                 <details open>
  31.                                     <summary><h5>January</h5></summary>
  32.                                     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac convallis eros. Sed nulla odio, accumsan luctus interdum eu, porttitor et augue. Proin imperdiet elementum ipsum, at tristique nibh congue quis. Maecenas nibh justo, mattis ac aliquet et, lobortis eu risus. </p>
  33.                                 </details>
  34.                             </div>
  35.                         </li>
  36.                         <li>
  37.                             <div class="timeline-item-container">
  38.                                 <details>
  39.                                     <summary><h5>Febuary</h5></summary>
  40.                                     <p>Cras porta orci eu fermentum egestas. Vestibulum non libero lacus. Nulla nec dignissim justo. Maecenas molestie bibendum blandit. Sed malesuada nulla diam, vel bibendum turpis egestas eget. Sed suscipit purus eu lorem hendrerit finibus.</p>
  41.                                 </details>
  42.                             </div>
  43.                         </li>
  44.                         <li>
  45.                             <div class="timeline-item-container">
  46.                                 <details>
  47.                                     <summary><h5>March</h5></summary>
  48.                                     <p>Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas in odio vitae dui molestie tempor. Morbi elementum blandit felis ac condimentum.</p>
  49.                                 </details>
  50.                             </div>
  51.                         </li>
  52.                         <li>
  53.                             <div class="timeline-item-container">
  54.                                 <details open>
  55.                                     <summary><h5>April</h5></summary>
  56.                                     <p>Aenean lacus purus, accumsan et ornare nec, fermentum sit amet libero. Vivamus eu tellus vitae augue convallis suscipit vel at mi. Fusce ornare tortor in lorem interdum faucibus.</p>
  57.                                 </details>
  58.                             </div>
  59.                         </li>
  60.                         <li>
  61.                             <div class="timeline-item-container">
  62.                                 <details>
  63.                                     <summary><h5>May</h5></summary>
  64.                                     <p>Praesent non consectetur lacus. Suspendisse ornare tempus erat at porttitor. Phasellus id aliquet ex. Curabitur eu leo est. Aenean vulputate egestas tincidunt. Integer ornare lacinia dolor, ut euismod lectus lobortis eu.</p>
  65.                                 </details>
  66.                             </div>
  67.                         </li>
  68.                     </ul>
  69.                 </div>
  70.             </div>
  71.         </div>
  72.         <footer class="shadow-top py-4 col-auto bg-dark text-light">
  73.             <div class="">
  74.                 <div class="text-center">
  75.                     All Rights Reserved &copy; <span id="dt-year"></span> | <span class="text-light fw-bolder">CSS - Timeline</span>
  76.                 </div>
  77.                 <div class="text-center">
  78.                     <a href="mailto:[email protected]" class="text-decoration-none text-light">[email protected]</a>
  79.                 </div>
  80.             </div>
  81.         </footer>
  82.     </main>
  83. </body>
  84. </html>

Without CSS script for the Timeline design, the page will look like the following image by default:

Simple Vertical Timeline using HTML and CSS

Unordered List and Items Design

Next, we will customize the design of the unordered list and list items.

  1. /** Timeline Design **/
  2. #timeline-container{
  3.     width:100%;
  4.     position: relative;
  5.     display: flex;
  6.     justify-content: center;
  7. }
  8. #timeline-list{
  9.     margin-left: 0px;
  10.     padding-left: 0px;
  11.     width: 100%;
  12. }
  13.  
  14. /** Removing List bullets */
  15. #timeline-list li {
  16.     list-style: none;
  17.     position: relative;
  18. }

Customizing the Items Panel or Card

Next, customize the design of the list items panel or the container that holds the timeline items.

  1. /** Styling the list Card/Panel Container */
  2. #timeline-list li .timeline-item-container{
  3.     padding-bottom: 1em;
  4.     padding-left: 0px;
  5. }
  6. #timeline-list details {
  7.     width: calc(50% - 20px);
  8.     border: 1px solid #dbdbdb;
  9.     box-shadow: 1px 1px 5px #bbb;
  10.     position: relative;
  11.     background:#fff;
  12.     overflow: hidden;
  13.     margin: 0 10px;
  14. }
  15. #timeline-list summary{
  16.     padding: .5em 1em;
  17.     list-style-type: none;
  18.     border-bottom: 1px solid #dddddd;
  19. }
  20. #timeline-list details p{
  21.     padding: .5em 1em;
  22.     margin: 1em .2em ;
  23. }
  24. /** changing the even items to right-to-left direction  */
  25. #timeline-list li:nth-child(even){
  26.   direction: rtl;
  27. }

The below image is the output of the customized item panel.

Simple Vertical Timeline using HTML and CSS

Creating the Timeline Vertical line and custom bullets

Next, let's create the vertical line and custom bullets of the timeline using the ::before and ::after pseudo-elements.

  1. /** Creating a Vertical line and custom bullets for each item */
  2. #timeline-list li:nth-child(odd):before{
  3.     content: "";
  4.     position: absolute;
  5.     height: 100%;
  6.     width: calc(50% + 1.5px);
  7.     border-right: 3px solid #dbdbdb;
  8. }
  9. #timeline-list li:nth-child(even):before{
  10.     content: "";
  11.     position: absolute;
  12.     height: 100%;
  13.     width: calc(50% + 1.5px);
  14.     border-right: 3px solid #dbdbdb;
  15.     right: calc(50% - 1.5px);
  16. }
  17.  
  18. #timeline-list li:after {
  19.     content: "";
  20.     position: absolute;
  21.     height: 10px;
  22.     width: 10px;
  23.     border-radius: 50% 50%;
  24.     background-color: #bbbbbb;
  25.     left: calc(50% - 4.5px);
  26.     top: 20px;
  27. }

Simple Vertical Timeline using HTML and CSS

Changing the Timeline Layout in Mobile View

Lastly, let's create the script that will change the layout of the time for mobile devices.

  1. /* If Device is Mobile */
  2. @media (max-width:480px){
  3.     #timeline-list li:nth-child(even){
  4.     direction: ltr;
  5.     }
  6.     #timeline-list details{
  7.     width:calc(100% - 20px);
  8.     }
  9.     #timeline-list li:before
  10.     {
  11.     width: 0 !important;
  12.     right: 100% !important;
  13.     }
  14.     #timeline-list li:after {
  15.     left: -6.5px !important;
  16.     }
  17. }

Simple Vertical Timeline using HTML and CSS

That's it! The timeline will look like the following image after we include the timeline CSS scripts for the design.

Simple Vertical Timeline using HTML and CSS

I have also provided the complete source code that I created for this tutorial on this website and it is free to download. You can download it by clicking the Download button located below this tutorial's content.

There you go! I hope this Creating a Simple Vertical Infographic Timeline using HTML and CSS Tutorial will help you with what you are looking for and will be useful for current and future web application projects.

Explore more on this website for more Tutorials and Free Source Codes.

Happy Coding =)

Add new comment