JSFiddle - React, Tailwind, and code Playground

by Venkatesh Dematti

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Scrollable Tags with Arrows</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 20px;
    }

    .tags-wrapper {
      position: relative;
      display: flex;
      align-items: center;
    }

    .tags-container {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      overflow: hidden;
      padding: 10px 0;
      flex-grow: 1;
      position: relative;
    }

    .tags-container.mobile {
      flex-wrap: nowrap;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: none; /* Hide scrollbar on Firefox */
    }

    .tags-container.mobile::-webkit-scrollbar {
      display: none; /* Hide scrollbar on Webkit */
    }

    .tag {
      background-color: #f1f1f1;
      color: #333;
      padding: 10px 15px;
      border-radius: 20px;
      white-space: nowrap;
      flex-shrink: 0; /* Prevent shrinking on mobile */
      cursor: pointer;
    }

    .fade-effect {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 50px;
      pointer-events: none;
      z-index: 1;
    }

    .fade-effect.left {
      left: 0;
      background: linear-gradient(to right, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));
    }

    .fade-effect.right {
      right: 0;
      background: linear-gradient(to left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));
    }

    .arrow {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      width: 30px;
      height: 30px;
      background-color: #ddd;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      z-index: 2;
      opacity: 1;/* Initially hide both arrows */
      transition: opacity 0.2s ease-in-out;
    }

    .arrow.left {
      left: 10px;
    }

    .arrow.right {
      right: 10px;
    }

...