Stock Price UI (Mock / API) with HTML, CSS & JavaScript

30 DAYS 30 PROJECT CHALLENGE

Day #25

Project Overview

A Stock Price UI built using HTML, CSS, and JavaScript that displays stock prices and daily changes in a clean and interactive interface.
The project uses mock data to simulate real stock market behavior while maintaining an API-ready structure, making it easy to integrate live stock data in the future.

Key Features

  • Displays stock prices with daily percentage change.
  • Uses mock data to simulate real-time market behavior.
  • Visual indicators for price increase and decrease.
  • Clean, responsive, and user-friendly interface.
  • API-ready structure for future real-time integration.
  • Suitable for learning financial UI design and data handling.

HTML Code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Stock Price UI</title>
  <link rel="stylesheet" href="style.css" />
</head>
<body>

  <div class="stock-container">
    <h2>Stock Price Tracker</h2>

    <select id="stockSelect">
      <option value="AAPL">Apple (AAPL)</option>
      <option value="GOOGL">Google (GOOGL)</option>
      <option value="AMZN">Amazon (AMZN)</option>
      <option value="MSFT">Microsoft (MSFT)</option>
      <option value="TSLA">Tesla (TSLA)</option>
    </select>

    <button onclick="getStock()">Get Price</button>

    <div id="result" class="result"></div>
  </div>

  <script src="script.js"></script>
</body>
</html>

CSS Code

* {
  box-sizing: border-box;
  font-family: "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  background: #042453;
  display: flex;
  justify-content: center;
  align-items: center;
}

.stock-container {
  background: #ffffff;
  width: 330px;
  padding: 25px;
  border-radius: 14px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}

h2 {
  margin-bottom: 15px;
}

select {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #ccc;
  margin-bottom: 10px;
}

button {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: #4f46e5;
  color: white;
  cursor: pointer;
}

.result {
  margin-top: 15px;
  font-size: 14px;
  font-weight: 600;
}

.up {
  color: green;
}

.down {
  color: red;
}

Javascript Code

const result = document.getElementById("result");

// Mock stock prices (for frontend demo)
const stockData = {
  AAPL: { price: 189.25, change: +1.35 },
  GOOGL: { price: 138.10, change: -0.82 },
  AMZN: { price: 145.60, change: +0.55 },
  MSFT: { price: 378.90, change: +2.10 },
  TSLA: { price: 212.45, change: -1.75 }
};

function getStock() {
  const stock = document.getElementById("stockSelect").value;
  const data = stockData[stock];

  const changeClass = data.change >= 0 ? "up" : "down";
  const sign = data.change >= 0 ? "+" : "";

  result.innerHTML = `
    📈 <strong>${stock}</strong><br><br>
    Price: $${data.price}<br>
    <span class="${changeClass}">
      Change: ${sign}${data.change}%
    </span>
  `;
}
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Projects

Day 23 : GitHub User Finder

Searches and displays GitHub user profiles using the GitHub public API.

Concepts: API fetching, async data handling, dynamic UI rendering.

Day 27 : Recipe Finder App

Searches and displays recipes dynamically using a public food API.

Concepts: API integration, async data fetching, dynamic UI rendering.

Day 28 : Language Translator

Translates text between multiple languages using a public translation API.

Concepts: API integration, async data handling, form handling, dynamic UI updates.