• Home
  • /
  • Profile Card with Light/Dark Theme using HTML CSS & JS

Profile Card with Light/Dark Theme Toggle using HTML CSS & JavaScript

HTML

				
					<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Profile Card with Theme</title>
  <link rel="stylesheet" href="style.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
</head>
<body>
  
  <!-- Theme Toggle Switch -->
<div class="theme-toggle">
  <label class="switch">
    <input type="checkbox" id="themeCheckbox">
    <span class="slider">
      <i class="fas fa-moon icon moon"></i>
      <i class="fas fa-sun icon sun"></i>
    </span>
    <span class="label-text">Light mode</span>
  </label>
</div>


  <!-- Profile Card -->
  <div class="card">
    <img decoding="async" src="Profile.jpg" class="profile-img" alt="Arshyan" />
    <h2>Arshyan Ali</h2>
    <div class='code-block code-block-2' style='margin: 8px 0; clear: both;'>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2094722033678002"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-2094722033678002"
     data-ad-slot="2248279416"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
<p class="role">Creative Frontend Developer passionate about UI/UX design</p>

    <button class="follow-btn">Follow Me</button>

    <div class="social-icons">
      <a href="#" class="facebook"><i class="fab fa-facebook-f"></i></a>
      <a href="#" class="youtube"><i class="fab fa-youtube"></i></a>
      <a href="#" class="tiktok"><i class="fab fa-tiktok"></i></a>
    </div>
  </div>

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

CSS

				
					/* Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', sans-serif;
  background: #e0e5ec;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  transition: background 0.4s ease;
}

/* Theme Toggle */
.theme-toggle {
  margin-bottom: 30px;
}

.switch {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.switch input {
  display: none;
}

.slider {
  position: relative;
  width: 60px;
  height: 30px;
  background: #ccc;
  border-radius: 30px;
  transition: background-color 0.3s ease;
}

.slider::before {
  content: "";
  position: absolute;
  height: 26px;
  width: 26px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  z-index: 2;
  transition: transform 0.3s ease;
}

.icon {
  position: absolute;
  font-size: 14px;
  color: #555;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  transition: opacity 0.3s ease;
}

body.dark .icon {
  color: white;
}

.moon {
  left: 10px;
  opacity: 0;
}

.sun {
  right: 10px;
  opacity: 1;
}

.label-text {
  margin-left: 12px;
  font-weight: 600;
  font-size: 16px;
  color: #333;
}

/* Toggle Active */
input:checked + .slider {
  background: #444;
}

input:checked + .slider::before {
  transform: translateX(30px);
}

input:checked + .slider .moon {
  opacity: 1;
}

input:checked + .slider .sun {
  opacity: 0;
}



/* Profile Card */
.card {
  background: #ffffff;
  padding: 30px;
  border-radius: 20px;
  box-shadow: 10px 10px 25px #bebebe, -10px -10px 25px #ffffff;
  text-align: center;
  width: 90%;
  max-width: 380px;
  transition: background 0.4s ease, box-shadow 0.4s ease;
}

.profile-img {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 4px solid #0162ff;
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  margin-bottom: 20px;
}

body.dark .profile-img {
  border: 4px solid white;
  
}

.card h2 {
  font-size: 24px;
  margin-bottom: 10px;
  color: #2a2d32;
}

.card .role {
  font-size: 14px;
  color: #555;
  margin-bottom: 20px;
}

.follow-btn {
  padding: 10px 20px;
  border: none;
  background: linear-gradient(to right, #6a11cb, #2575fc);
  color: white;
  border-radius: 30px;
  font-size: 15px;
  cursor: pointer;
  margin-bottom: 20px;
}

.social-icons {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.social-icons a {
  text-decoration: none;
  width: 42px;
  height: 42px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  font-size: 18px;
  transition: all 0.3s ease;
}

.facebook {
  background: #e0e5ec;
  color: #0162ff;
  box-shadow: 5px 5px 10px #bebebe, -5px -5px 10px #ffffff;
}

.youtube {
  background: #e0e5ec;
  color: #ff0000;
  box-shadow: 5px 5px 10px #bebebe, -5px -5px 10px #ffffff;
}

.tiktok {
  background: #e0e5ec;
  color: #000;
  box-shadow: 5px 5px 10px #bebebe, -5px -5px 10px #ffffff;
}


.social-icons a:hover {
  transform: scale(1.1);
}

/* Individual Colors */
.facebook {
  color: #3b5998;
}
.youtube {
  color: #ff0000;
}
.tiktok {
  color: #000;
}

/* Dark Mode */


body.dark .card {
  background: #2a2d32;
  box-shadow: inset 6px 6px 12px #1c1e21, inset -6px -6px 12px #3c4149;
}

body.dark .card h2,
body.dark .card .role {
  color: #eee;
}

body.dark .facebook {
  background: #0162ff;
  box-shadow: inset 5px 5px 10px #0d47a1, inset -5px -5px 10px #1e88e5;
  color: white;
}

body.dark .youtube {
  background: #ff0000;
  box-shadow: inset 5px 5px 10px #b71c1c, inset -5px -5px 10px #f44336;
  color: white;
}

body.dark .tiktok {
  background: #000;
  box-shadow: inset 5px 5px 10px #1c1c1c, inset -5px -5px 10px #333;
  color: white;
}

				
			

JavaScript

				
					const themeToggle = document.getElementById('themeCheckbox');
const labelText = document.querySelector('.label-text');

themeToggle.addEventListener('change', () => {
  document.body.classList.toggle('dark');
  labelText.textContent = document.body.classList.contains('dark')
    ? 'Dark mode'
    : 'Light mode';
});
				
			

Share this post

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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

Scroll to Top