Portfolio Website Using JavaScript
Last Updated :
06 Aug, 2025
Previously, we created a responsive portfolio website using HTML and CSS, giving it a clean structure and visually appealing design. Now, we’ll enhance it further by adding JavaScript to introduce interactivity and improve user experience. Features like dark mode, typing animation, a scroll-to-top button, and a mobile menu toggle will make the portfolio dynamic and engaging. Let’s explore how JavaScript can bring your static website to life.
Portfolio Source Code
Let's start by setting up the HTML structure for our portfolio website (as previously mentioned)
filename: index.html
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Portfolio of John Doe</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1 style="text-align:center;">John Doe</h1>
<p style="text-align:center;">Home | Projects | Blogs | Contact</p>
</header>
<h2 style="text-align:center;">Web Developer and Designer</h2>
<table border="1" width="100%">
<tr>
<td>
<h3>Portfolio Highlights</h3>
<ul>
<li>Responsive HTML Layout</li>
<li>E-commerce Storefront</li>
<li>Interactive Form Design</li>
<li>Event Countdown Widget</li>
<li>Prototype Landing Pages</li>
</ul>
</td>
<td>
<h3>Career Achievements</h3>
<p>Frontend Developer [Intern] at XYZ<br>Headed major product redesigns resulting in a 40% increase in user engagement.<br><a href="#">View My LinkedIn Profile</a></p>
<h3>Community Involvement</h3>
<p>Active participant in local and online developer forums. Regularly contribute to web development blogs and GitHub projects.<br><a href="#">Visit My GitHub</a></p>
</td>
<td>
<h3>Academic Qualifications</h3>
<p>B.Tech (Computer Science) from ABC University</p>
<p>Specializations:</p>
<ul>
<li>Systems Analysis</li>
<li>Advanced JavaScript Techniques</li>
<li>Web Accessibility Standards</li>
<li>Performance Optimization in Web Applications</li>
<li>Cloud Computing Infrastructure</li>
<li>Security in Web Applications</li>
<li>Advanced Algorithms</li>
</ul>
</td>
</tr>
</table>
<h3>Peer Reviews</h3>
<table border="1" width="100%">
<tr>
<td>John Doe consistently delivers high-quality, innovative solutions that exceed project expectations. - Steven, Project Lead</td>
<td>John Doe is known for his precise attention to detail and his ability to mentor younger developers. - David, UI Designer</td>
<td>John's approach to problem-solving has been instrumental in our success. - Sarah, Frontend Developer</td>
</tr>
</table>
<footer style="text-align:center;">
© [2025] All rights reserved by John Doe
</footer>
<script src="script.js"></script>
</body>
</html>
- Defines the structure of the portfolio with sections: Home, About, Projects, and Contact.
- Includes a navigation bar for smooth scrolling to different sections on the same page.
- Links external CSS (
style.css
) for styling and JavaScript (index.js
) for interactivity. - Provides a simple layout with headings, paragraphs, and list elements to showcase information.
filename: styles.css
styles.css
/* Reset default margins and paddings */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Body styling */
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
color: #333;
background-color: #f5f5f5;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
/* Header styling */
header {
background-color: #2c3e50;
color: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
}
header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
header p {
font-size: 1.1em;
}
header p a {
color: #3498db;
text-decoration: none;
margin: 0 10px;
transition: color 0.3s;
}
header p a:hover {
color: #2980b9;
}
/* Main heading */
h2 {
color: #2c3e50;
margin: 20px 0;
font-size: 1.8em;
}
/* Table styling */
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
background-color: white;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
table td {
padding: 20px;
vertical-align: top;
border: 1px solid #ddd;
}
h3 {
color: #2c3e50;
margin-bottom: 15px;
font-size: 1.4em;
}
/* List styling */
ul {
list-style-type: none;
padding-left: 20px;
}
ul li {
margin-bottom: 10px;
position: relative;
}
ul li::before {
content: '•';
color: #3498db;
position: absolute;
left: -20px;
}
/* Links */
a {
color: #3498db;
text-decoration: none;
transition: color 0.3s;
}
a:hover {
color: #2980b9;
text-decoration: underline;
}
/* Paragraph spacing */
p {
margin-bottom: 10px;
}
/* Footer styling */
footer {
background-color: #2c3e50;
color: white;
padding: 15px;
border-radius: 8px;
margin-top: 20px;
}
/* Responsive design */
@media (max-width: 768px) {
table {
display: block;
}
table tr {
display: block;
margin-bottom: 20px;
}
table td {
display: block;
border: none;
border-bottom: 1px solid #ddd;
}
header h1 {
font-size: 2em;
}
h2 {
font-size: 1.5em;
}
h3 {
font-size: 1.2em;
}
}
- Resets default styles and applies consistent font, colors, and spacing across the page.
- Styles the header, navigation, sections, and footer for a clean, modern look.
- Adds hover effects for links and visual enhancements like shadows and rounded corners.
- Ensures responsive design with centered content and mobile-friendly layouts.
filename: script.js
script.js
// Dark Mode Toggle
const toggleDarkMode = () => {
document.body.classList.toggle('dark-mode');
};
// Add dark mode button
const darkModeBtn = document.createElement('button');
darkModeBtn.innerText = 'Toggle Dark Mode';
darkModeBtn.style.position = 'fixed';
darkModeBtn.style.bottom = '20px';
darkModeBtn.style.right = '20px';
darkModeBtn.style.padding = '10px';
darkModeBtn.style.backgroundColor = '#3498db';
darkModeBtn.style.color = '#fff';
darkModeBtn.style.border = 'none';
darkModeBtn.style.borderRadius = '5px';
darkModeBtn.style.cursor = 'pointer';
darkModeBtn.onclick = toggleDarkMode;
document.body.appendChild(darkModeBtn);
// Dark mode styles
const darkStyle = document.createElement('style');
darkStyle.innerHTML = `
.dark-mode {
background-color: #1a1a1a;
color: #f5f5f5;
}
.dark-mode table {
background-color: #2c2c2c;
}
.dark-mode header, .dark-mode footer {
background-color: #111;
}
.dark-mode a {
color: #1abc9c;
}
`;
document.head.appendChild(darkStyle);
// Typing Animation for Title
const title = document.querySelector('h2');
const text = "Web Developer and Designer";
let index = 0;
const typeEffect = () => {
if (index < text.length) {
title.innerHTML += text.charAt(index);
index++;
setTimeout(typeEffect, 100);
}
};
title.innerHTML = "";
typeEffect();
// Smooth Scroll Navigation (for demonstration)
const navLinks = document.querySelectorAll('header p');
navLinks.forEach(link => {
link.style.cursor = 'pointer';
link.onclick = () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
};
});
// Popup Modal for Peer Reviews
const peerReviewTable = document.querySelectorAll('table')[1];
peerReviewTable.querySelectorAll('td').forEach((td, i) => {
td.style.cursor = 'pointer';
td.onclick = () => showModal(td.innerText);
});
const showModal = (text) => {
const modal = document.createElement('div');
modal.style.position = 'fixed';
modal.style.top = '0';
modal.style.left = '0';
modal.style.width = '100%';
modal.style.height = '100%';
modal.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
modal.style.display = 'flex';
modal.style.justifyContent = 'center';
modal.style.alignItems = 'center';
modal.style.zIndex = '1000';
const modalContent = document.createElement('div');
modalContent.style.background = '#fff';
modalContent.style.padding = '20px';
modalContent.style.borderRadius = '10px';
modalContent.style.maxWidth = '600px';
modalContent.innerHTML = `<p>${text}</p><button style="margin-top:10px;">Close</button>`;
modalContent.querySelector('button').onclick = () => document.body.removeChild(modal);
modal.appendChild(modalContent);
document.body.appendChild(modal);
};
// Dynamic Year in Footer
const footer = document.querySelector('footer');
footer.innerHTML = `© ${new Date().getFullYear()} All rights reserved by John Doe`;
// Scroll to Top Button
const scrollBtn = document.createElement('button');
scrollBtn.innerText = '↑ Top';
scrollBtn.style.position = 'fixed';
scrollBtn.style.bottom = '60px';
scrollBtn.style.right = '20px';
scrollBtn.style.padding = '10px';
scrollBtn.style.backgroundColor = '#2c3e50';
scrollBtn.style.color = '#fff';
scrollBtn.style.border = 'none';
scrollBtn.style.borderRadius = '5px';
scrollBtn.style.cursor = 'pointer';
scrollBtn.style.display = 'none';
scrollBtn.onclick = () => window.scrollTo({ top: 0, behavior: 'smooth' });
document.body.appendChild(scrollBtn);
// Show button when scrolling down
window.onscroll = () => {
scrollBtn.style.display = window.scrollY > 200 ? 'block' : 'none';
};
Output:
- Dark Mode Toggle: Adds a floating button that lets users switch between light and dark themes dynamically, improving accessibility and user comfort.
- Typing Animation: Creates a typing effect for the main title ("Web Developer and Designer") to make the page more visually engaging.
- Interactive Peer Reviews: Allows users to click on peer review text and view it in a styled popup modal for better readability and user interaction.
- Scroll Features & Dynamic Year: Adds a "Scroll to Top" button for smooth navigation and automatically updates the footer with the current year.
Now your portfolio website isn’t just a static structure — it’s visually appealing and professional too. With the help of CSS, you’ve brought your content to life using colors, spacing, fonts, and layout enhancements.
But don’t stop here — take your design skills further by experimenting:
- Customize the look with unique color schemes and gradients.
- Try different font families and sizes to match your personal style.
- Add hover effects, transitions, and animations for an engaging user experience.
- Organize your styles using external CSS for cleaner, scalable code.
Similar Reads
Web Development Technologies Web development refers to building, creating, and maintaining websites. It includes aspects such as web design, web publishing, web programming, and database management. It is the creation of an application that works over the internet, i.e., websites.Basics of Web Development : To better understand
7 min read
HTML Tutorial
CSS Tutorial CSS stands for Cascading Style Sheets. It is a stylesheet language used to style and enhance website presentation. CSS is one of the three main components of a webpage, along with HTML and JavaScript.HTML adds Structure to a web page.JavaScript adds logic to it and CSS makes it visually appealing or
7 min read
JS Tutorial
JavaScript TutorialJavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.Client Side: On the client side, JavaScript works
11 min read
JSON TutorialJSON (JavaScript Object Notation) is a widely-used, lightweight data format for representing structured data. Used Extensively : Used in APIs, configuration files, and data exchange between servers and clients.Text-based: JSON is a simple text format, making it lightweight and easy to transmit.Human
5 min read
TypeScript TutorialTypeScript is a superset of JavaScript that adds extra features like static typing, interfaces, enums, and more. Essentially, TypeScript is JavaScript with additional syntax for defining types, making it a powerful tool for building scalable and maintainable applications.Static typing allows you to
8 min read
Vue.js TutorialVue.js is a progressive JavaScript framework for building user interfaces. It stands out for its simplicity, seamless integration with other libraries, and reactive data binding.Built on JavaScript for flexible and component-based development.Supports declarative rendering, reactivity, and two-way d
4 min read
jQuery TutorialjQuery is a lightweight JavaScript library that simplifies the HTML DOM manipulating, event handling, and creating dynamic web experiences. The main purpose of jQuery is to simplify the usage of JavaScript on websites. jQuery achieves this by providing concise, single-line methods for complex JavaSc
8 min read
Front End
React TutorialReact is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
Angular TutorialAngular is a powerful, open-source web application framework for building dynamic and scalable single-page applications (SPAs). Developed by Google, Angular provides a comprehensive solution for front-end development with tools for routing, form handling, HTTP services, and more.Designed for buildin
4 min read
Backend
Node.js TutorialNode.js is a powerful, open-source, and cross-platform JavaScript runtime environment built on Chrome's V8 engine. It allows you to run JavaScript code outside the browser, making it ideal for building scalable server-side and networking applications.JavaScript was mainly used for frontend developme
4 min read
Express.js TutorialExpress.js is a minimal and flexible Node.js web application framework that provides a list of features for building web and mobile applications easily. It simplifies the development of server-side applications by offering an easy-to-use API for routing, middleware, and HTTP utilities.Built on Node.
4 min read
PHP TutorialPHP is a popular, open-source scripting language mainly used in web development. It runs on the server side and generates dynamic content that is displayed on a web application. PHP is easy to embed in HTML, and it allows developers to create interactive web pages and handle tasks like database mana
9 min read
Laravel TutorialLaravel is an open-source PHP web application framework that has gained immense popularity since its inception in 2011, created by Taylor Otwell. This renowned framework empowers developers to build robust, scalable web applications with remarkable ease. As a developer-friendly framework, Laravel of
3 min read
Database
Web Technologies Questions The following Web Technologies Questions section contains a wide collection of web-based questions. These questions are categorized based on the topics HTML, CSS, JavaScript, and many more. Each section contains a bulk of questions with multiple solutions. Table of Content HTML QuestionsCSS Question
15+ min read