Open In App

Portfolio Website Using JavaScript

Last Updated : 06 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

Article Tags :

Similar Reads