sasaass

HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Single HTML Page with Multiple Sections</title> <link rel="stylesheet" href="styles.css"> </head> <body> <nav> <ul> <li><a href="#" onclick="showPage('home')">Home</a></li> <li><a href="#" onclick="showPage('about')">About Us</a></li> <li><a href="#" onclick="showPage('contact')">Contact</a></li> </ul> </nav> <section id="home"> <h2>Welcome to our website!</h2> <p>This is the home page content.</p> </section> <section id="about"> <h2>About Us</h2> <p>Here you can find information about our company.</p> </section> <section id="contact"> <h2>Contact</h2> <p>Contact us for any inquiries or feedback.</p> </section> <script src="script.js"></script> </body> </html>
CSS
/* styles.css */ body { font-family: Arial, sans-serif; margin: 0; padding: 0; } nav { background-color: #333; color: white; padding: 10px; } nav ul { list-style-type: none; padding: 0; } nav ul li { display: inline; margin-right: 10px; } section { padding: 20px; display: none; }
JAVASCRIPT
// script.js function showPage(pageId) { document.querySelectorAll('section').forEach(section => { section.style.display = 'none'; }); document.getElementById(pageId).style.display = 'block'; }
Expand for more options Login