• We just launched and are currently in beta. Join us as we build and grow the community.

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

DavidMaix

Digital Media Expert
D Rep
0
0
0
Rep
0
D Vouches
0
0
0
Vouches
0
Posts
160
Likes
199
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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.

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. <head

    >
  4. <meta

    charset

    =

    "UTF-8"

    >
  5. <meta

    http-equiv

    =

    "X-UA-Compatible"

    content

    =

    "IE=edge"

    >
  6. <meta

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1.0"

    >
  7. <title

    >

    HTML/CSS/JS - Admin Template</

    title

    >
  8. <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"

    /

    >
  9. <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

    >
  10. <link

    rel

    =

    "preconnect"

    href

    =

    "https://fonts.googleapis.com"

    >
  11. <link

    rel

    =

    "preconnect"

    href

    =

    "https://fonts.gstatic.com"

    crossorigin>
  12. <link

    href

    =

    "https://fonts.googleapis.com/css2?family=Amatic+SC:wght@700&display=swap"

    rel

    =

    "stylesheet"

    >
  13. <link

    rel

    =

    "stylesheet"

    href

    =

    "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"

    >
  14. <link

    rel

    =

    "stylesheet"

    href

    =

    "assets/css/styles.css"

    >
  15. <script

    src

    =

    "https://code.jquery.com/jquery-3.6.1.js"

    integrity=

    "sha256-3zlB5s2uwoUzrXK3BT7AX3FyvojsraNFxCc2vC/7pNI="

    crossorigin=

    "anonymous"

    ></

    script

    >
  16. <script

    src

    =

    "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"

    ></

    script

    >
  17. </

    head

    >
  18. <body

    >
  19. <main>
  20. <nav

    class

    =

    "navbar navbar-expand-lg navbar-light bg-gradient bg-light py-0 shadow"

    id

    =

    "TopNav"

    >
  21. <div

    id

    =

    "navBarBrand-container"

    >
  22. <a

    class

    =

    "navbar-brand"

    href

    =

    "./"

    >

    ADMIN - TEMPLATE</

    a

    >
  23. </

    div

    >
  24. <div

    id

    =

    "navBarMenu-container"

    >
  25. <div

    class

    =

    "ct-top-nav-left"

    >
  26. <button

    id

    =

    "SideBarToggle"

    >
  27. <i

    class

    =

    "fa fa-bars"

    ></

    i

    >
  28. </

    button

    >
  29. <a

    class

    =

    "navbar-brand"

    href

    =

    "./"

    >

    Responsive Custom Admin Template</

    a

    >
  30. <div

    class

    =

    "collapse navbar-collapse"

    id

    =

    "navbarNav"

    >
  31. </

    div

    >
  32. </

    div

    >
  33. <div

    class

    =

    "ct-top-nav-right"

    >
  34. <a

    href

    =

    "https://sourcecodester.com"

    class

    =

    "text-body fw-bolder h6 text-decoration-none"

    target

    =

    "_blank"

    >

    SourceCodester</

    a

    >
  35. </

    div

    >
  36. </

    div

    >
  37. </

    nav

    >
  38. <div

    id

    =

    "sidebarNav"

    >
  39. <ul

    class

    =

    "nav-menu"

    >
  40. <li

    class

    =

    "nav-item"

    >
  41. <div

    class

    =

    "nav-icon"

    >
  42. <i

    class

    =

    "fa fa-dashboard"

    ></

    i

    >
  43. </

    div

    >
  44. <a

    href

    =

    "#"

    class

    =

    "nav-link"

    >

    Dashboard</

    a

    >
  45. </

    li

    >
  46. <li

    class

    =

    "nav-item active"

    >
  47. <div

    class

    =

    "nav-icon"

    >
  48. <i

    class

    =

    "fa fa-th-list"

    ></

    i

    >
  49. </

    div

    >
  50. <a

    href

    =

    "#"

    class

    =

    "nav-link"

    >

    Menu 1</

    a

    >
  51. </

    li

    >
  52. <li

    class

    =

    "nav-item"

    >
  53. <div

    class

    =

    "nav-icon"

    >
  54. <i

    class

    =

    "fa fa-th-list"

    ></

    i

    >
  55. </

    div

    >
  56. <a

    href

    =

    "#"

    class

    =

    "nav-link"

    >

    Menu 2</

    a

    >
  57. </

    li

    >
  58. <li

    class

    =

    "nav-item"

    >
  59. <div

    class

    =

    "nav-icon"

    >
  60. <i

    class

    =

    "fa fa-th-list"

    ></

    i

    >
  61. </

    div

    >
  62. <a

    href

    =

    "#"

    class

    =

    "nav-link"

    >

    Menu 3</

    a

    >
  63. </

    li

    >
  64. </

    ul

    >
  65. </

    div

    >
  66. <div

    id

    =

    "main-wrapper"

    class

    =

    "py-5 px-3"

    >
  67. <div

    class

    =

    "container-fluid-md"

    >
  68. <h1

    class

    =

    "text-center"

    ><b

    >

    HTML/CSS/JS - Admin Template with Bootstrap 5.3 Framework</

    b

    ></

    h1

    >
  69. <hr

    class

    =

    "border-3 border-dark mx-auto opacity-100"

    style

    =

    "width:80px"

    >

  70. </

    div

    >
  71. </

    div

    >
  72. <footer

    class

    =

    "shadow-top py-4 col-auto bg-light text-dark"

    id

    =

    "footer"

    >
  73. <div

    class

    =

    ""

    >
  74. <div

    class

    =

    "text-center"

    >
  75. All Rights Reserved &copy;

    <span

    id

    =

    "dt-year"

    ></

    span

    >

    | <span

    class

    =

    "text-body fw-bolder"

    >

    HTML/CSS/JS - Admin Template</

    span

    >
  76. </

    div

    >
  77. <div

    class

    =

    "text-center"

    >
  78. <a

    href

    =

    "mailto:[email protected]"

    class

    =

    "text-decoration-none text-body"

    >

    [email protected]</

    a

    >
  79. </

    div

    >
  80. </

    div

    >
  81. </

    footer

    >
  82. </

    main>
  83. <script

    src

    =

    "./assets/js/custom-admin-template.js"

    ></

    script

    >
  84. </

    body

    >
  85. </

    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. /* Wrapper Design */
  12. main{
  13. width

    :

    100%

    ;
  14. height

    :

    100%

    ;
  15. overflow

    :

    hidden

    ;
  16. display

    :

    flex;
  17. flex-direction

    :

    column;
  18. }
  19. main>

    nav,
  20. main>

    footer
  21. {
  22. width

    :

    100%

    ;
  23. flex-shrink

    :

    1

    ;
  24. }
  25. main>

    div#main-wrapper
  26. {
  27. width

    :

    100%

    ;
  28. flex-grow

    :

    1

    ;
  29. height

    :

    calc

    (

    100%

    )

    ;
  30. overflow

    :

    auto

    ;
  31. }

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. /* Topbar title and menu container design */
  23. #navBarMenu-container

    {
  24. display

    :

    flex;
  25. align-items

    :

    center

    ;
  26. justify-content

    :

    space-between;
  27. padding

    :

    15px

    30px

    15px

    10px

    ;
  28. }
  29. #navBarMenu

    .ct-top-nav-left{
  30. width

    :

    60%

    ;
  31. }
  32. #navBarMenu

    .ct-top-nav-right{
  33. width

    :

    40%

    ;
  34. }
  35. #navBarMenu-container

    a{
  36. white-space

    :

    break-spaces;
  37. }
  38. button

    #SideBarToggle

    {
  39. background

    :

    transparent

    ;
  40. border

    :

    unset;
  41. }
  42. button

    #SideBarToggle

    *

    {
  43. color

    :

    #2d2d2d

    ;
  44. }

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. }


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. window.cusotmAdminTemplate

    =

    function

    (

    )

    {
  10. var

    sb_is_toggle =

    !!

    SideBarToggle.getAttribute

    (

    'data-toggle'

    )

    &&

    SideBarToggle.getAttribute

    (

    'data-toggle'

    )

    ==

    "true"

    ;
  11. if

    (

    sb_is_toggle)

    {
  12. customSideBar.style

    .width

    =

    0

    ;
  13. customFooter.style

    .width

    =

    (

    window.innerWidth

    )

    +

    `px`;
  14. customFooter.style

    .marginLeft

    =

    `0px`;
  15. MainWrapper.style

    .width

    =

    (

    window.innerWidth

    )

    +

    `px`;
  16. MainWrapper.style

    .marginLeft

    =

    `0px`;
  17. // For laptop, desktop, or bigger screens only
  18. if

    (

    window.innerWidth

    >

    768

    )
  19. NavBarBrand.style

    .width

    =

    `auto`;
  20. }

    else

    {
  21. if

    (

    window.innerWidth

    >

    768

    )

    {
  22. // For laptop, desktop, or bigger screens only
  23. if

    (

    customSideBar.clientWidth

    ==

    0

    )
  24. customSideBar.style

    .width

    =

    SideBarwidth +

    `px`;
  25. customSideBar.style

    .height

    =

    (

    window.innerHeight

    -

    customTopBar.clientHeight

    )

    +

    `px`;
  26. customSideBar.style

    .marginTop

    =

    (

    customTopBar.clientHeight

    )

    +

    `px`;
  27. customFooter.style

    .width

    =

    (

    window.innerWidth

    -

    SideBarwidth)

    +

    `px`;
  28. customFooter.style

    .marginLeft

    =

    (

    SideBarwidth)

    +

    `px`;
  29. NavBarBrand.style

    .width

    =

    SideBarwidth +

    `px`;
  30. NavBarMenu.style

    .width

    =

    (

    window.innerWidth

    -

    SideBarwidth)

    +

    `px`;
  31. MainWrapper.style

    .width

    =

    (

    window.innerWidth

    -

    SideBarwidth)

    +

    `px`;
  32. MainWrapper.style

    .marginLeft

    =

    (

    SideBarwidth)

    +

    `px`;
  33. }

    else

    {
  34. // For mobile, tablets, or smaller screens only
  35. if

    (

    customSideBar.clientWidth

    ==

    0

    )
  36. customSideBar.style

    .width

    =

    SideBarwidth +

    `px`;
  37. customFooter.style

    .width

    =

    (

    window.innerWidth

    )

    +

    `px`;
  38. customFooter.style

    .marginLeft

    =

    `0px`;
  39. MainWrapper.style

    .width

    =

    (

    window.innerWidth

    )

    +

    `px`;
  40. MainWrapper.style

    .marginLeft

    =

    `0px`;
  41. customSideBar.style

    .height

    =

    (

    window.innerHeight

    -

    customTopBar.clientHeight

    )

    +

    `px`;
  42. customSideBar.style

    .marginTop

    =

    (

    customTopBar.clientHeight

    )

    +

    `px`;
  43. }

  44. }

  45. }
  46. cusotmAdminTemplate(

    )

    ;
  47. window.onload

    =

    function

    (

    )

    {
  48. cusotmAdminTemplate(

    )

    ;
  49. // hide sidebar as default for smaller screens
  50. if

    (

    window.innerWidth

    <=

    768

    )

    {
  51. SideBarToggle.setAttribute

    (

    'data-toggle'

    ,

    "true"

    )
  52. customSideBar.style

    .width

    =

    `0px`;
  53. }
  54. // enable the sidebar vissibility
  55. setTimeout(

    function

    (

    )

    {
  56. customSideBar.style

    .opacity

    =

    '1'
  57. }

    ,

    300

    )
  58. }

  59. /** Update containers sizes when resizing the window screen */
  60. window.onresize

    =

    function

    (

    )

    {
  61. cusotmAdminTemplate(

    )

    ;
  62. }

  63. /**
  64. * Toggle SideBar
  65. */
  66. SideBarToggle.addEventListener

    (

    'click'

    ,

    function

    (

    )

    {
  67. if

    (

    !!

    SideBarToggle.getAttribute

    (

    'data-toggle'

    )

    &&

    SideBarToggle.getAttribute

    (

    'data-toggle'

    )

    ==

    "true"

    )

    {
  68. SideBarToggle.setAttribute

    (

    'data-toggle'

    ,

    "false"

    )
  69. }

    else

    {
  70. SideBarToggle.setAttribute

    (

    'data-toggle'

    ,

    "true"

    )
  71. }
  72. cusotmAdminTemplate(

    )

    ;
  73. }

    )

Output

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

Desktop, Laptop, and Bigger Screen Devices

Tablet Device (Portrait)

Mobile Device (hidden sidebar)

Mobile Device (sidebar toggled)

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 =)


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,158

323,328

323,337

Top