Skip to content

tllanka/Pure-CSS-HTML-JS-Tabs-Panel-and-content-tabs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Pure CSS, HTML, and JS Tabs Panel: A Simple Solution for Navigation

Tabs Panel

Table of Contents

Overview

Welcome to the Pure-CSS-HTML-JS-Tabs-Panel-and-content-tabs repository. This project offers a clean and effective way to create tabbed navigation and content panels using only native HTML, CSS, and JavaScript. You can explore the Releases section for the latest updates and downloads.

This solution avoids the complexity of frameworks and libraries, providing a straightforward method for nesting content into tabs. It supports lazy loading and dynamic content generation, making it flexible for various use cases.

Features

  • No Dependencies: Built with pure HTML, CSS, and JavaScript.
  • Flexible Content Nesting: Easily nest different types of content within tabs.
  • Lazy Loading: Load content only when needed to improve performance.
  • Extensible: Modify and expand functionality as needed.
  • Simple Implementation: Quick to set up and easy to understand.

Getting Started

To get started, you need to clone this repository to your local machine. You can do this using the following command:

git clone https://github.com/tllanka/Pure-CSS-HTML-JS-Tabs-Panel-and-content-tabs.git

Navigate to the project directory:

cd Pure-CSS-HTML-JS-Tabs-Panel-and-content-tabs

Open the index.html file in your web browser to see the tabs in action.

Usage

The basic structure of the tab panel includes HTML elements that define the tabs and the corresponding content. Below is a simple example:

<div class="tabs">
    <button class="tab-button active" onclick="openTab(event, 'Tab1')">Tab 1</button>
    <button class="tab-button" onclick="openTab(event, 'Tab2')">Tab 2</button>
    <button class="tab-button" onclick="openTab(event, 'Tab3')">Tab 3</button>
</div>

<div id="Tab1" class="tab-content active">
    <h3>Tab 1 Content</h3>
    <p>This is the content for Tab 1.</p>
</div>

<div id="Tab2" class="tab-content">
    <h3>Tab 2 Content</h3>
    <p>This is the content for Tab 2.</p>
</div>

<div id="Tab3" class="tab-content">
    <h3>Tab 3 Content</h3>
    <p>This is the content for Tab 3.</p>
</div>

JavaScript Functionality

To switch between tabs, use the following JavaScript function:

function openTab(evt, tabName) {
    var i, tabcontent, tabbuttons;

    tabcontent = document.getElementsByClassName("tab-content");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";  
    }

    tabbuttons = document.getElementsByClassName("tab-button");
    for (i = 0; i < tabbuttons.length; i++) {
        tabbuttons[i].className = tabbuttons[i].className.replace(" active", "");
    }

    document.getElementById(tabName).style.display = "block";  
    evt.currentTarget.className += " active";
}

This function hides all tab contents and shows the selected one, providing a smooth user experience.

Examples

Explore various examples to see how the tabs can be implemented in different scenarios:

  1. Basic Tabs: Simple navigation with static content.
  2. Dynamic Content: Load content dynamically based on user actions.
  3. Nested Tabs: Create tabs within tabs for more complex layouts.

You can find these examples in the examples directory of the repository.

Customization

You can easily customize the look and feel of the tabs by modifying the CSS. Here are a few properties you might want to change:

.tab-button {
    background-color: #f1f1f1;
    border: none;
    cursor: pointer;
    padding: 10px;
}

.tab-button.active {
    background-color: #ccc;
}

.tab-content {
    display: none;
    padding: 20px;
    border: 1px solid #ccc;
}

Feel free to add your own styles to match your website's design.

Accessibility

Accessibility is important for web applications. Ensure that your tab panels are usable for everyone by following these guidelines:

  • Use aria-selected attributes to indicate the active tab.
  • Implement keyboard navigation to allow users to switch tabs using the keyboard.
  • Provide clear labels for each tab and content area.

Example of adding ARIA attributes:

<button class="tab-button" aria-selected="true">Tab 1</button>

Contributing

We welcome contributions from the community. If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add new feature').
  5. Push to the branch (git push origin feature-branch).
  6. Open a pull request.

Please ensure that your code adheres to the existing style and includes tests where applicable.

License

This project is licensed under the MIT License. Feel free to use it in your own projects.

For the latest updates and releases, visit the Releases section.

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages