How to Create Free TV Streaming App and Website

Here is all the information needed to create a Free TV Streaming App and Website.

Prompt Used:

Create a single-page HTML web app for Free TV streaming with these features:

‎- Sticky header with:

‎  - Hamburger menu to toggle sidebar

‎  - Dynamic title showing current channel

‎  - Search bar for filtering channels

‎  - Buttons to add custom channel and toggle light/dark theme

‎- Sidebar categories: Live, Favorites, Recently Watched, News, Sports, Kids, Movies, Religion

‎  - Slide-in/out on mobile

‎  - Highlight active category

‎- Main content:

‎  - Responsive video player (HLS support, autoplay, controls, playsinline)

‎  - Expandable/minimizable player

‎  - Grid of channel cards with logo, name, favorite button

‎  - Clicking a card plays that channel

‎  - Max 80 channels displayed

‎  - Lazy-load images

‎- Functionalities:

‎  - Load channels from `.m3u` playlists

‎  - Parse #EXTINF for logo, name, URL

‎  - Favorites and recent channels saved in localStorage

‎  - Real-time search filter

‎  - Add custom channel via prompt

‎  - Light/dark theme toggle stored in localStorage

‎- Responsive design for desktop, tablet, mobile

‎- Modern clean UI with subtle shadows, hover effects

‎- Use CSS variables for colors

‎- All code in a single HTML file with embedded CSS and JS

‎- Include HLS.js from CDN

‎Generate a full, ready-to-run HTML file implementing all features.

The Code used

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF--8" />
  <title>Free TV Streaming</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <style>
    :root {
      --bg-main: #121212;
      --bg-sidebar: #1e1e1e;
      --bg-item: #2c2c2c;
      --text-color: #fff;
      --accent: #444;
      --border-color: #333;
    }
    body.light {
      --bg-main: #f5f5f5;
      --bg-sidebar: #ffffff;
      --bg-item: #eaeaea;
      --text-color: #000;
      --accent: #ddd;
      --border-color: #ccc;
    }

    body {
      margin: 0;
      font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
      background: var(--bg-main);
      color: var(--text-color);
      display: flex;
      flex-direction: column;
      height: 100vh;
      overflow: hidden;
      transition: background 0.3s, color 0.3s;
    }

    .header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 12px;
      padding: 12px 16px;
      background: var(--bg-sidebar);
      border-bottom: 1px solid var(--border-color);
      position: sticky;
      top: 0;
      z-index: 100;
    }
    .header-left {
      display: flex;
      align-items: center;
      gap: 10px;
      /* Allow header title to shrink */
      min-width: 0;
    }
    .menu-btn {
      font-size: 24px;
      cursor: pointer;
      border: none;
      background: none;
      color: var(--text-color);
      flex-shrink: 0; /* Prevent button from shrinking */
    }
    .header h1 {
      margin: 0;
      font-size: 18px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .header-actions {
      display: flex;
      gap: 8px;
      align-items: center;
    }
    .header-actions input {
      flex: 1;
      min-width: 140px;
      max-width: 260px;
      padding: 8px 12px;
      border-radius: 20px;
      border: none;
      outline: none;
      font-size: 14px;
      background: var(--bg-item);
      color: var(--text-color);
    }
    .pill-btn {
      padding: 8px 12px;
      border: none;
      border-radius: 20px;
      cursor: pointer;
      background: var(--bg-item);
      color: var(--text-color);
      transition: background 0.2s;
      white-space: nowrap;
    }
    .pill-btn:hover { background: var(--accent); }

    .content {
      flex: 1;
      display: flex;
      overflow: hidden;
      position: relative;
    }

    .sidebar {
      position: absolute;
      top: 0;
      bottom: 0;
      left: -240px; /* Adjusted width */
      width: 240px;  /* Adjusted width */
      background: var(--bg-sidebar);
      border-right: 1px solid var(--border-color);
      display: flex;
      flex-direction: column;
      padding: 10px 0;
      transition: left 0.3s ease;
      z-index: 200;
    }
    .sidebar.open { left: 0; }
    .sidebar button {
      background: none;
      border: none;
      font-size: 16px;
      color: var(--text-color);
      padding: 14px 18px;
      text-align: left;
      cursor: pointer;
      transition: background 0.2s;
    }
    .sidebar button:hover,
    .sidebar button.active { background: var(--accent); }

    main {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      width: 100%;
    }

    .player {
      flex: 0 0 46%;
      background: #000;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative; /* For potential overlays */
    }
    video { width: 100%; height: 100%; background: #000; }

    .channel-grid {
      flex: 1;
      overflow-y: auto;
      padding: 16px;
      background: var(--bg-main);
      display: grid;
      /* Responsive grid columns */
      grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
      gap: 14px;
    }
    .channel-card {
      background: var(--bg-item);
      border-radius: 12px;
      padding: 12px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
      transition: transform 0.15s ease, box-shadow 0.15s ease;
      cursor: pointer;
    }
    .channel-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.25); }
    .channel-card img {
      width: 100%;
      height: 90px; /* Adjusted height */
      object-fit: contain;
      border-radius: 8px;
      background: #000;
    }
    .channel-card h3 {
      margin: 0;
      font-size: 14px;
      text-align: center;
    }
    .fav-btn {
      border: none;
      background: none;
      font-size: 18px;
      cursor: pointer;
      color: #aaa;
    }
    .fav-btn.active { color: gold; }

    /* Overlay for sidebar on mobile */
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 199;
        display: none;
    }
    .sidebar.open + main .overlay {
        display: block;
    }


    /* --- Media Queries for Responsiveness --- */

    /* For Tablets and smaller devices */
    @media (max-width: 768px) {
      main {
        /* Change to vertical layout on smaller screens */
        flex-direction: column;
      }
      .player {
        /* Aspect ratio for video player */
        flex-basis: auto;
        width: 100%;
        padding-top: 56.25%; /* 16:9 Aspect Ratio */
        position: relative;
      }
      video {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
      }
      .header-actions input {
        min-width: 110px;
        max-width: 160px;
      }
    }

    /* For Mobile Phones */
    @media (max-width: 480px) {
      .header h1 {
        font-size: 16px; /* Slightly smaller title */
      }
      .header-actions input {
        /* Hide search bar by default */
        width: 36px;
        min-width: 36px;
        padding-left: 10px;
        padding-right: 10px;
        border-radius: 50%;
        cursor: pointer;
        transition: width 0.3s ease-in-out;
        background: var(--bg-item) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="white" viewBox="0 0 16 16"><path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"/></svg>') no-repeat center;
      }
      .header-actions input:focus {
        /* Expand search bar on focus */
        width: 150px;
        max-width: 180px;
        border-radius: 20px;
        cursor: text;
        background-image: none;
      }
      .pill-btn {
        padding: 8px 10px; /* Slightly reduce padding */
      }
      .channel-grid {
        /* Adjust grid for smaller screens */
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        padding: 12px;
        gap: 12px;
      }
      .channel-card img {
          height: 75px; /* Adjust image height */
      }
      .channel-card h3 {
          font-size: 13px; /* Smaller font for card titles */
      }
    }

  </style>
</head>
<body>
  

Continuation of the codes

<div class="header">
    <div class="header-left">
      <button class="menu-btn" onclick="toggleMenu()">☰</button>
      <h1>Free TV</h1>
    </div>
    <div class="header-actions">
      <input id="searchBar" type="text" placeholder="Search..." oninput="applyFilters()" />
      <button class="pill-btn" onclick="addCustomChannel()">➕</button>
      <button class="pill-btn" onclick="toggleTheme()">🌙/☀️</button>
    </div>
  </div>

  <div class="content">
    <aside class="sidebar" id="sidebar">
      <button class="active" onclick="loadCategory('live', this); closeMenu();">🏠 Live</button>
      <button onclick="loadCategory('favorites', this); closeMenu();">⭐ Favorites</button>
      <button onclick="loadCategory('recent', this); closeMenu();">⏱ Recently Watched</button>
      <button onclick="loadCategory('news', this); closeMenu();">📰 News</button>
      <button onclick="loadCategory('sports', this); closeMenu();">⚽ Sports</button>
      <button onclick="loadCategory('kids', this); closeMenu();">🧒 Kids</button>
      <button onclick="loadCategory('movies', this); closeMenu();">🎬 Movies</button>
      <button onclick="loadCategory('religion', this); closeMenu();">🙏 Religion</button>
    </aside>

    <main>
      <div class="overlay" onclick="toggleMenu()"></div>
      <div class="player">
        <video id="tvPlayer" controls autoplay playsinline></video>
      </div>
      <div class="channel-grid" id="channels"></div>
    </main>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
  <script>
    const playlists = {
      live: "https://iptv-org.github.io/iptv/index.m3u",
      favorites: "",
      recent: "",
      news: "https://iptv-org.github.io/iptv/categories/news.m3u",
      sports: "https://iptv-org.github.io/iptv/categories/sports.m3u",
      kids: "https://iptv-org.github.io/iptv/categories/animation.m3u",
      movies: "https://iptv-org.github.io/iptv/categories/movies.m3u",
      religion: "https://iptv-org.github.io/iptv/categories/religious.m3u",
    };

    const playerEl = document.getElementById("tvPlayer");
    const sidebar = document.getElementById("sidebar");
    const channelsEl = document.getElementById("channels");

    let hls;
    let allChannels = [];
    let filteredChannels = [];
    let favorites = JSON.parse(localStorage.getItem("favorites") || "[]");
    let recent = JSON.parse(localStorage.getItem("recent") || "[]");

    function toggleMenu() { sidebar.classList.toggle("open"); }
    // Function to close menu, useful on mobile after selection
    function closeMenu() {
        if (window.innerWidth <= 768) {
            sidebar.classList.remove("open");
        }
    }


    function loadCategory(category, btn) {
      document.querySelectorAll(".sidebar button").forEach(b => b.classList.remove("active"));
      if (btn) btn.classList.add("active");

      document.querySelector(".header h1").textContent = "Free TV";

      if (category === "favorites") {
        allChannels = favorites;
        applyFilters();
        if (allChannels.length) playChannel(allChannels[0].url, allChannels[0]);
        return;
      }
      if (category === "recent") {
        allChannels = recent;
        applyFilters();
        if (allChannels.length) playChannel(allChannels[0].url, allChannels[0]);
        return;
      }

      fetch(playlists[category])
        .then(r => r.text())
        .then(text => {
          const lines = text.split("\n");
          const channels = [];
          let ch = {};
          for (const line of lines) {
            if (line.startsWith("#EXTINF")) {
              const logoMatch = line.match(/tvg-logo="([^"]*)"/);
              const name = line.split(",").pop().trim();
              ch = { logo: logoMatch ? logoMatch[1] : "", name: name || "Unknown" };
            } else if (/^https?:\/\//.test(line)) {
              ch.url = line.trim();
              channels.push({ ...ch });
            }
          }
          allChannels = channels;
          applyFilters();
          if (channels.length) playChannel(channels[0].url, channels[0]);
        })
        .catch(err => console.error("Playlist load error:", err));
    }

    function applyFilters() {
      const q = (document.getElementById("searchBar").value || "").toLowerCase();
      filteredChannels = allChannels.filter(ch => !q || ch.name.toLowerCase().includes(q));
      renderChannels(filteredChannels);
    }

    function renderChannels(channels) {
      channelsEl.innerHTML = "";
      channels.slice(0, 80).forEach(ch => {
        const card = document.createElement("div");
        card.className = "channel-card";
        card.onclick = () => playChannel(ch.url, ch);

        const img = document.createElement("img");
        img.src = ch.logo || "https://via.placeholder.com/300x180?text=TV";
        img.loading = "lazy";
        card.appendChild(img);

        const title = document.createElement("h3");
        title.textContent = ch.name;
        card.appendChild(title);

        const favBtn = document.createElement("button");
        favBtn.className = "fav-btn";
        const isFav = favorites.some(f => f.url === ch.url);
        favBtn.innerHTML = isFav ? "⭐" : "☆";
        if (isFav) favBtn.classList.add("active");
        favBtn.onclick = (e) => { e.stopPropagation(); toggleFavorite(ch, favBtn); };
        card.appendChild(favBtn);

        channelsEl.appendChild(card);
      });
    }

    function playChannel(url, ch) {
      try { if (hls) { hls.destroy(); hls = null; } } catch(e) {}
      if (Hls.isSupported()) {
        hls = new Hls();
        hls.loadSource(url);
        hls.attachMedia(playerEl);
      } else {
        playerEl.src = url;
      }
      playerEl.play().catch(() => {});

      if (ch && ch.name) {
        document.querySelector(".header h1").textContent = ch.name;
      }

      if (ch) {
        recent = recent.filter(r => r.url !== ch.url);
        recent.unshift(ch);
        if (recent.length > 20) recent.pop();
        localStorage.setItem("recent", JSON.stringify(recent));
      }
    }

    function toggleFavorite(ch, btn) {
      const i = favorites.findIndex(f => f.url === ch.url);
      if (i >= 0) {
        favorites.splice(i, 1);
        btn.innerHTML = "☆";
        btn.classList.remove("active");
      } else {
        favorites.push(ch);
        btn.innerHTML = "⭐";
        btn.classList.add("active");
      }
      localStorage.setItem("favorites", JSON.stringify(favorites));
    }

    function addCustomChannel() {
      const name = prompt("Channel name?");
      const url = prompt("Channel stream URL (.m3u8)?");
      if (name && url) {
        const newCh = { name, url, logo: "" };
        favorites.push(newCh);
        localStorage.setItem("favorites", JSON.stringify(favorites));
        alert("✅ Added to Favorites!");
      }
    }

    function toggleTheme() {
      document.body.classList.toggle("light");
      localStorage.setItem("theme", document.body.classList.contains("light") ? "light" : "dark");
    }

    window.onload = () => {
      const savedTheme = localStorage.getItem("theme");
      if (savedTheme === "light") document.body.classList.add("light");
      loadCategory("live", document.querySelector(".sidebar button"));
    };
  </script>
</body>
</html>

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *