Creating a Responsive Custom Admin Template using HTML, CSS, JS, and Bootstrap 5.3

In this tutorial, I will show you how to create a Simple and Responsive Admin Template using HTML, CSS, JavaScript, and Bootstrap 5.3 Framework. The purpose of this tutorial is to provide the students, self-learners, and beginners with a reference to learn how to build a simple and responsive template using the said languages and CSS Framework. Here, snippets and source codes of a sample web application page that demonstrates a Responsive Admin Template are provided. The source code is also provided on this site and it is free to download.

What is Admin Template?

Admin Template is a collection of page interface components created using HTML, CSS, JavaScript, and any CSS and JavaScript Libraries. This template is commonly used in a web application that contains multiple features such as the admin or management site of a content management system. Developers used this type of template as the user interface to help their users to navigate to site pages easily.

Creating a Simple Responsive Admin Template with Bootstrap 5.3 Framework

The below snippets and scripts are the codes that will output a web page with an Admin Template using HTML, CSS, JavaScript, and Bootstrap 5.3. The Bootstrap Framework's assets are only loaded using CDN which means an internet connection is needed to properly display the page interface.

Target Template View

In this tutorial, we will create an admin template with a top bar, sidebar, footer, and content wrapper. See the following image to have a visual idea about this.

Responsive Admin Template using Bootstrap 5.3

HTML

The script below is the HTML code of the web page that contains the elements we need for creating the template.

  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>HTML/CSS/JS - Admin Template</title>
  7.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
  8.     <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/js/all.min.js" integrity="sha512-2bMhOkE/ACz21dJT8zBOMgMecNxx0d37NND803ExktKiKdSzdwn+L7i9fdccw/3V06gM/DBWKbYmQvKMdAA9Nw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  9.     <link rel="preconnect" href="https://fonts.googleapis.com">
  10.     <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  11.     <link href="https://fonts.googleapis.com/css2?family=Amatic+SC:wght@700&display=swap" rel="stylesheet">
  12.     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
  13.     <link rel="stylesheet" href="assets/css/styles.css">
  14.     <script src="https://code.jquery.com/jquery-3.6.1.js" integrity="sha256-3zlB5s2uwoUzrXK3BT7AX3FyvojsraNFxCc2vC/7pNI=" crossorigin="anonymous"></script>
  15.     <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
  16. </head>
  17.     <main>
  18.         <nav class="navbar navbar-expand-lg navbar-light bg-gradient bg-light py-0 shadow" id="TopNav">
  19.             <div id="navBarBrand-container">
  20.                 <a class="navbar-brand" href="./">ADMIN - TEMPLATE</a>
  21.             </div>
  22.             <div id="navBarMenu-container">
  23.                 <div class="ct-top-nav-left">
  24.                     <button id="SideBarToggle">
  25.                         <i class="fa fa-bars"></i>
  26.                     </button>
  27.                     <a class="navbar-brand" href="./">Responsive Custom Admin Template</a>
  28.                     <div class="collapse navbar-collapse" id="navbarNav">
  29.                     </div>
  30.                 </div>
  31.                 <div class="ct-top-nav-right">
  32.                     <a href="https://sourcecodester.com" class="text-body fw-bolder h6 text-decoration-none" target="_blank">SourceCodester</a>
  33.                 </div>
  34.             </div>
  35.         </nav>
  36.         <div id="sidebarNav">
  37.             <ul class="nav-menu">
  38.                 <li class="nav-item">
  39.                     <div class="nav-icon">
  40.                         <i class="fa fa-dashboard"></i>
  41.                     </div>
  42.                     <a href="#" class="nav-link">Dashboard</a>
  43.                 </li>
  44.                 <li class="nav-item active">
  45.                     <div class="nav-icon">
  46.                         <i class="fa fa-th-list"></i>
  47.                     </div>
  48.                     <a href="#" class="nav-link">Menu 1</a>
  49.                 </li>
  50.                 <li class="nav-item">
  51.                     <div class="nav-icon">
  52.                         <i class="fa fa-th-list"></i>
  53.                     </div>
  54.                     <a href="#" class="nav-link">Menu 2</a>
  55.                 </li>
  56.                 <li class="nav-item">
  57.                     <div class="nav-icon">
  58.                         <i class="fa fa-th-list"></i>
  59.                     </div>
  60.                     <a href="#" class="nav-link">Menu 3</a>
  61.                 </li>
  62.             </ul>
  63.         </div>
  64.         <div id="main-wrapper" class="py-5 px-3">
  65.             <div class="container-fluid-md">
  66.                 <h1 class="text-center"><b>HTML/CSS/JS - Admin Template with Bootstrap 5.3 Framework</b></h1>
  67.                 <hr class="border-3 border-dark mx-auto opacity-100" style="width:80px">
  68.                
  69.             </div>
  70.         </div>
  71.         <footer class="shadow-top py-4 col-auto bg-light text-dark" id="footer">
  72.             <div class="">
  73.                 <div class="text-center">
  74.                     All Rights Reserved &copy; <span id="dt-year"></span> | <span class="text-body fw-bolder">HTML/CSS/JS - Admin Template</span>
  75.                 </div>
  76.                 <div class="text-center">
  77.                     <a href="mailto:[email protected]" class="text-decoration-none text-body">[email protected]</a>
  78.                 </div>
  79.             </div>
  80.         </footer>
  81.     </main>
  82.     <script src="./assets/js/custom-admin-template.js"></script>
  83. </body>
  84. </html>

Wrapper Design

Next, let's create the CSS script for the design of the wrapper, to prevent overlays of the content on each part of the template.

  1.     /** Font Famaily **/
  2.     h1, h2, h3, h4, h5, h6{
  3.       font-family: 'Amatic SC', cursive;
  4.     }
  5.     html, body{
  6.       height: 100%;
  7.       width: 100%;
  8.       overflow-x: hidden;
  9.     }
  10.     /** Custom Admin Template Design **/
  11.    
  12.     /* Wrapper Design */
  13.     main{
  14.       width: 100%;
  15.       height: 100%;
  16.       overflow: hidden;
  17.       display: flex;
  18.       flex-direction: column;
  19.     }
  20.     main>nav,
  21.     main>footer
  22.     {
  23.       width: 100%;
  24.       flex-shrink: 1;
  25.     }
  26.     main>div#main-wrapper
  27.     {
  28.       width: 100%;
  29.       flex-grow: 1;
  30.       height: calc(100%);
  31.       overflow: auto;
  32.     }

Customization of Top Bar

Next, let's customize the Bootstrap navbar according to the template we want to achieve.

  1. /* Customizing Top bar Design */
  2. /* NavBar Brand */
  3. #navBarBrand-container{
  4.     display: flex;
  5.     flex-wrap: wrap;
  6.     overflow: hidden;
  7.     padding: 0 15px;
  8.     justify-content: center;
  9.     align-items: center;
  10.     background: #202020;
  11.     min-height: calc(100%);
  12. }
  13. #navBarBrand-container .navbar-brand{
  14.     white-space: break-spaces;
  15.     font-size: 1.5rem;
  16.     font-weight: bolder;
  17.     text-align: center;
  18. }
  19. #navBarBrand-container * {
  20.     color:#fff;
  21. }
  22.  
  23. /* Topbar title and menu container design */
  24. #navBarMenu-container{
  25.     display: flex;
  26.     align-items: center;
  27.     justify-content: space-between;
  28.     padding: 15px 30px 15px 10px;
  29. }
  30. #navBarMenu .ct-top-nav-left{
  31.     width: 60%;
  32. }
  33. #navBarMenu .ct-top-nav-right{
  34.     width: 40%;
  35. }
  36. #navBarMenu-container a{
  37.     white-space: break-spaces;
  38. }
  39. button#SideBarToggle {
  40.     background: transparent;
  41.     border: unset;
  42. }
  43. button#SideBarToggle *{
  44.     color: #2d2d2d;
  45. }

Creating the Sidebar Design

Next, we'll create the sidebar design. The design of the sidebar will be only simple with multiple page links that have a :hover and .active design.

  1. /* Sidebar Navigation */
  2. #sidebarNav{
  3.     width: 350px;
  4.     position: fixed;
  5.     left:0;
  6.     min-height: 60vh;
  7.     background: #202020;
  8.     transition: width .3s ease-in-out;
  9.     opacity: 0;
  10.     overflow: hidden;
  11. }
  12. #sidebarNav .nav-menu{
  13.     width: calc(100%);
  14.     overflow: auto;
  15.     padding: 0;
  16. }
  17. #sidebarNav .nav-menu .nav-item:nth-child(1) {
  18.     border-top: 2px solid #505050;
  19. }
  20. #sidebarNav .nav-menu .nav-item {
  21.     min-height: 55px;
  22.     display: flex;
  23.     list-style: none;
  24.     padding: 0 10px;
  25.     align-items: center;
  26.     border-bottom: 1px solid #505050;
  27. }
  28. #sidebarNav .nav-menu .nav-item:hover {
  29.     background: #363636;
  30. }
  31. #sidebarNav .nav-menu .nav-item.active {
  32.     background: #fff;
  33. }
  34. #sidebarNav .nav-menu .nav-item>.nav-icon {
  35.     flex-shrink: 1;
  36.     font-size: 23px;
  37.     display: flex;
  38.     align-items: center;
  39.     justify-content: center;
  40.     width: 60px;
  41. }
  42. #sidebarNav .nav-menu .nav-item>.nav-link {
  43.     flex-grow: 1;
  44.     font-size: 1.2rem;
  45.     font-weight: 600;
  46. }
  47. #sidebarNav .nav-menu .nav-item>.nav-link,
  48. #sidebarNav .nav-menu .nav-item>.nav-icon
  49. {
  50.     color: #ededed;
  51. }
  52. #sidebarNav .nav-menu .nav-item.active * {
  53.     color: #363636;
  54. }

Footer and Transition

Next, add the additional CSS script for the design of the footer and the transition of the panel.

  1. footer#footer {
  2.     box-shadow: 0px 0px 22px #d7d7d7;
  3. }
  4. #main-wrapper,
  5. #navBarMenu-container,
  6. #navBarBrand-container,
  7. #footer{
  8.   transition: width .3s ease-in-out,  margin .3s ease-in-out;
  9. }

Tablet and Mobile View Design

Next, create the script that overwrites some of the provided CSS scripts for devices with a smaller screen such as tablets and mobile devices.

  1. /* Customize Admin Template in Tablets, mobile, and smaller screens */
  2. @media (max-width:768px){
  3.     #TopNav{
  4.     display: flex;
  5.     height: auto;
  6.     }
  7.     #navBarBrand-container,
  8.     #navBarMenu-container,
  9.     #footer
  10.     {
  11.     width: 100% !important;
  12.     }
  13.     #navBarBrand-container{
  14.     min-height: unset;
  15.     }
  16.     #sidebarNav{
  17.     z-index: 99;
  18.     box-shadow: 0px 2px 5px #000;
  19.     }
  20.     #sidebarNav .nav-menu .nav-item.active {
  21.     border-top-left-radius: unset;
  22.     border-bottom-left-radius: unset;
  23.     background: #fff;
  24.     }
  25. }
  26. @media (max-width:350px){
  27.     #sidebarNav{
  28.     width: 100%;
  29.     }
  30. }
  31.    

Creating the JavaScript

Lastly, let's create the scripts that will help the page interface be more responsive to any device screen resolutions, when the window screen is resized, and when the document is loaded successfully. Make sure to load this script on the HTML file.

  1.     const customTopBar = document.getElementById("TopNav")
  2.     const customSideBar = document.getElementById("sidebarNav")
  3.     const customFooter = document.getElementById("footer")
  4.     const NavBarBrand = document.getElementById("navBarBrand-container")
  5.     const NavBarMenu = document.getElementById("navBarMenu-container")
  6.     const MainWrapper = document.getElementById("main-wrapper")
  7.     const SideBarToggle = document.getElementById("SideBarToggle")
  8.     var SideBarwidth = customSideBar.clientWidth
  9.  
  10.     window.cusotmAdminTemplate = function(){
  11.         var sb_is_toggle = !!SideBarToggle.getAttribute('data-toggle') && SideBarToggle.getAttribute('data-toggle') == "true";
  12.         if(sb_is_toggle){
  13.             customSideBar.style.width = 0;
  14.             customFooter.style.width = (window.innerWidth) + `px`;
  15.             customFooter.style.marginLeft = `0px`;
  16.             MainWrapper.style.width =(window.innerWidth) + `px`;
  17.             MainWrapper.style.marginLeft = `0px`;
  18.             // For laptop, desktop, or bigger screens only
  19.             if(window.innerWidth > 768)
  20.             NavBarBrand.style.width = `auto`;
  21.         }else{
  22.             if(window.innerWidth > 768){
  23.                 // For laptop, desktop, or bigger screens only
  24.                 if(customSideBar.clientWidth == 0)
  25.                 customSideBar.style.width = SideBarwidth + `px`;
  26.                 customSideBar.style.height = (window.innerHeight -  customTopBar.clientHeight) + `px`;
  27.                 customSideBar.style.marginTop = (customTopBar.clientHeight) + `px`;
  28.                 customFooter.style.width = (window.innerWidth -  SideBarwidth) + `px`;
  29.                 customFooter.style.marginLeft = (SideBarwidth) + `px`;
  30.                 NavBarBrand.style.width = SideBarwidth + `px`;
  31.                 NavBarMenu.style.width =(window.innerWidth -  SideBarwidth) + `px`;
  32.                 MainWrapper.style.width =(window.innerWidth -  SideBarwidth) + `px`;
  33.                 MainWrapper.style.marginLeft = (SideBarwidth) + `px`;
  34.             }else{
  35.                 // For mobile, tablets, or smaller screens only
  36.                 if(customSideBar.clientWidth == 0)
  37.                     customSideBar.style.width = SideBarwidth + `px`;
  38.                 customFooter.style.width = (window.innerWidth) + `px`;
  39.                 customFooter.style.marginLeft = `0px`;
  40.                 MainWrapper.style.width =(window.innerWidth) + `px`;
  41.                 MainWrapper.style.marginLeft = `0px`;
  42.                 customSideBar.style.height = (window.innerHeight -  customTopBar.clientHeight) + `px`;
  43.                 customSideBar.style.marginTop = (customTopBar.clientHeight) + `px`;
  44.             }
  45.            
  46.         }
  47.        
  48.     }
  49.     cusotmAdminTemplate();
  50.     window.onload = function(){
  51.         cusotmAdminTemplate();
  52.         // hide sidebar as default for smaller screens
  53.         if(window.innerWidth <= 768){
  54.             SideBarToggle.setAttribute('data-toggle', "true")
  55.             customSideBar.style.width = `0px`;
  56.         }
  57.         // enable the sidebar vissibility
  58.         setTimeout(function(){
  59.             customSideBar.style.opacity = '1'
  60.         }, 300)
  61.     }
  62.  
  63.     /** Update containers sizes when resizing the window screen */
  64.     window.onresize = function(){
  65.         cusotmAdminTemplate();
  66.     }
  67.  
  68.     /**
  69.     * Toggle SideBar
  70.     */
  71.     SideBarToggle.addEventListener('click', function(){
  72.         if(!!SideBarToggle.getAttribute('data-toggle') && SideBarToggle.getAttribute('data-toggle') == "true"){
  73.             SideBarToggle.setAttribute('data-toggle', "false")
  74.         }else{
  75.             SideBarToggle.setAttribute('data-toggle', "true")
  76.         }
  77.         cusotmAdminTemplate();
  78.     })

Output

Here are the snapshots of the result of the page interface with an Admin Template.

Desktop, Laptop, and Bigger Screen Devices

Responsive Admin Template using Bootstrap 5.3

Tablet Device (Portrait)

Responsive Admin Template using Bootstrap 5.3

Mobile Device (hidden sidebar)

Responsive Admin Template using Bootstrap 5.3

Mobile Device (sidebar toggled)

Responsive Admin Template using Bootstrap 5.3

There you go! I have also provided the complete source code zip file that I created for this tutorial on this site and it is free to download. The download button is located below this tutorial's content. Feel free to download and modify it the way you wanted.

That's the end of this tutorial! I hope this Creating a Responsive Custom Admin Template using HTML, CSS, JS, and Bootstrap 5.3 Tutorial will help you with what you are looking for and will be useful for your current and future web application projects.

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

Happy Coding =)

Comments

Add new comment