Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Portfolio</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <header>
        <h1>My Portfolio</h1>
        <button id="theme-toggle">Toggle Dark Mode</button>
    </header>

    <section class="about">
        <h2>About Me</h2>
        <p>
            I am a passionate developer specializing in web development and Flutter applications.
        </p>
    </section>

    <section class="projects">
        <h2>Projects</h2>
        <div class="project">
            <h3>Project 1: Portfolio Website</h3>
            <p>A simple, responsive portfolio website with dark mode.</p>
        </div>
        <div class="project">
            <h3>Project 2: E-commerce Application</h3>
            <p>An e-commerce web app built with modern web technologies.</p>
        </div>
    </section>

    <section class="contact">
        <h2>Contact</h2>
        <p>Email: example@portfolio.com</p>
        <p>LinkedIn: <a href="#">My LinkedIn Profile</a></p>
    </section>

    <footer>
        <p>&copy; 2024 My Portfolio</p>
    </footer>

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

              
            
!

CSS

              
                /* General Styling */
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    transition: background-color 0.3s, color 0.3s;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background-color: #f0f0f0;
}

h1, h2, h3 {
    margin: 0;
}

button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    border: none;
    background-color: #007bff;
    color: white;
    border-radius: 5px;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #0056b3;
}

section {
    padding: 20px;
}

.projects .project {
    margin-bottom: 20px;
}

footer {
    padding: 10px;
    text-align: center;
    background-color: #f0f0f0;
}

/* Light Mode (Default) */
body.light-mode {
    background-color: white;
    color: black;
}

header.light-mode, footer.light-mode {
    background-color: #f0f0f0;
}

button.light-mode {
    background-color: #007bff;
}

/* Dark Mode */
body.dark-mode {
    background-color: #121212;
    color: #e0e0e0;
}

header.dark-mode, footer.dark-mode {
    background-color: #1f1f1f;
}

button.dark-mode {
    background-color: #28a745;
}

button.dark-mode:hover {
    background-color: #218838;
}

              
            
!

JS

              
                // script.js
document.addEventListener('DOMContentLoaded', () => {
    const themeToggleBtn = document.getElementById('theme-toggle');
    const body = document.body;

    // Check if the user has a preferred theme in localStorage
    const currentTheme = localStorage.getItem('theme') || 'light-mode';
    body.classList.add(currentTheme);

    // Update button text based on the current theme
    themeToggleBtn.textContent = body.classList.contains('dark-mode') 
        ? 'Switch to Light Mode' 
        : 'Switch to Dark Mode';

    // Toggle theme on button click
    themeToggleBtn.addEventListener('click', () => {
        body.classList.toggle('dark-mode');
        body.classList.toggle('light-mode');

        // Update button text based on the new theme
        themeToggleBtn.textContent = body.classList.contains('dark-mode') 
            ? 'Switch to Light Mode' 
            : 'Switch to Dark Mode';

        // Save the user's preference to localStorage
        const newTheme = body.classList.contains('dark-mode') ? 'dark-mode' : 'light-mode';
        localStorage.setItem('theme', newTheme);
    });
});

              
            
!
999px

Console