Create Code HTML CSS Javascript For Landing Page
- User
Create Code HTML CSS Javascript For Landing Page
- Assistant
Sure! Below is a simple yet modern landing page template using HTML, CSS, and JavaScript. This template includes a header with navigation, a hero section, feature sections, and a footer. Additionally, it includes a responsive navigation menu with a toggle button for smaller screens.
Project Structure
- index.html – The main HTML file.
- styles.css – The CSS file for styling.
- script.js – The JavaScript file for interactive functionality.
1.
index.html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Landing Page</title> <!-- Link to CSS --> <link rel="stylesheet" href="styles.css"> <!-- Google Fonts --> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet"> </head> <body> <!-- Header Section --> <header class="header"> <div class="container"> <div class="logo">MyBrand</div> <nav class="nav" id="nav"> <ul> <li><a href="#home" class="active">Home</a></li> <li><a href="#features">Features</a></li> <li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav> <div class="nav-toggle" id="nav-toggle"> <span></span> <span></span> <span></span> </div> </div> </header> <!-- Hero Section --> <section class="hero" id="home"> <div class="container"> <h1>Welcome to MyBrand</h1> <p>Your success is our priority. Let's build something great together.</p> <a href="#contact" class="btn">Get Started</a> </div> </section> <!-- Features Section --> <section class="features" id="features"> <div class="container"> <h2>Our Features</h2> <div class="feature-cards"> <div class="card"> <h3>Feature One</h3> <p>Describe your first amazing feature here.</p> </div> <div class="card"> <h3>Feature Two</h3> <p>Describe your second amazing feature here.</p> </div> <div class="card"> <h3>Feature Three</h3> <p>Describe your third amazing feature here.</p> </div> </div> </div> </section> <!-- About Section --> <section class="about" id="about"> <div class="container"> <h2>About Us</h2> <p>Provide information about your company or product here. Explain your mission, vision, and values.</p> </div> </section> <!-- Contact Section --> <section class="contact" id="contact"> <div class="container"> <h2>Contact Us</h2> <form id="contact-form"> <input type="text" id="name" name="name" placeholder="Your Name" required> <input type="email" id="email" name="email" placeholder="Your Email" required> <textarea id="message" name="message" rows="5" placeholder="Your Message" required></textarea> <button type="submit" class="btn">Send Message</button> </form> <div id="form-messages"></div> </div> </section> <!-- Footer --> <footer class="footer"> <div class="container"> <p>© 2023 MyBrand. All rights reserved.</p> </div> </footer> <!-- Link to JS --> <script src="script.js"></script> </body> </html>2.
styles.css/* General Styles */ * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Roboto', sans-serif; line-height: 1.6; color: #333; } .container { width: 90%; max-width: 1200px; margin: auto; } /* Header Styles */ .header { background: #fff; padding: 20px 0; border-bottom: 1px solid #eaeaea; position: fixed; width: 100%; top: 0; z-index: 1000; } .logo { float: left; font-size: 24px; font-weight: bold; } .nav { float: right; } .nav ul { list-style: none; display: flex; } .nav ul li { margin-left: 20px; } .nav ul li a { text-decoration: none; color: #333; font-weight: 500; transition: color 0.3s; } .nav ul li a:hover, .nav ul li a.active { color: #007BFF; } /* Navigation Toggle (Hamburger) */ .nav-toggle { display: none; flex-direction: column; cursor: pointer; } .nav-toggle span { height: 3px; width: 25px; background: #333; margin-bottom: 4px; border-radius: 5px; } /* Hero Section */ .hero { background: url('https://via.placeholder.com/1200x600') center center/cover no-repeat; height: 100vh; display: flex; align-items: center; justify-content: center; position: relative; padding-top: 80px; /* To offset fixed header */ } .hero::after { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); } .hero .container { position: relative; color: #fff; text-align: center; } .hero h1 { font-size: 48px; margin-bottom: 20px; } .hero p { font-size: 20px; margin-bottom: 30px; } .btn { display: inline-block; padding: 12px 30px; background: #007BFF; color: #fff; text-decoration: none; border-radius: 25px; transition: background 0.3s; } .btn:hover { background: #0056b3; } /* Features Section */ .features { padding: 80px 0; background: #f9f9f9; text-align: center; } .features h2 { margin-bottom: 40px; font-size: 32px; } .feature-cards { display: flex; justify-content: space-between; flex-wrap: wrap; } .card { background: #fff; padding: 20px; width: 30%; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); border-radius: 8px; transition: transform 0.3s; } .card:hover { transform: translateY(-10px); } .card h3 { margin-bottom: 15px; color: #007BFF; } .card p { color: #666; } /* About Section */ .about { padding: 80px 0; text-align: center; } .about h2 { margin-bottom: 20px; font-size: 32px; } .about p { color: #666; max-width: 800px; margin: auto; } /* Contact Section */ .contact { padding: 80px 0; background: #f9f9f9; text-align: center; } .contact h2 { margin-bottom: 40px; font-size: 32px; } .contact form { max-width: 600px; margin: auto; display: flex; flex-direction: column; } .contact input, .contact textarea { padding: 15px; margin-bottom: 20px; border: 1px solid #ddd; border-radius: 5px; font-size: 16px; } .contact button { align-self: center; } /* Footer Styles */ .footer { background: #333; color: #fff; padding: 20px 0; text-align: center; } /* Responsive Styles */ @media (max-width: 768px) { .nav { display: none; width: 100%; } .nav ul { flex-direction: column; background: #fff; } .nav ul li { margin: 10px 0; text-align: center; } .nav-toggle { display: flex; } .feature-cards { flex-direction: column; align-items: center; } .card { width: 80%; } }3.
script.js// Navigation Toggle for Mobile const navToggle = document.getElementById('nav-toggle'); const nav = document.getElementById('nav'); navToggle.addEventListener('click', () => { nav.classList.toggle('nav-open'); navToggle.classList.toggle('toggle-active'); }); // Smooth Scrolling const navLinks = document.querySelectorAll('.nav ul li a'); navLinks.forEach(link => { link.addEventListener('click', function(e) { e.preventDefault(); const targetId = this.getAttribute('href').substring(1); const targetSection = document.getElementById(targetId); window.scrollTo({ top: targetSection.offsetTop - 60, // Adjust for fixed header behavior: 'smooth' }); // Close the nav on mobile after clicking if (nav.classList.contains('nav-open')) { nav.classList.remove('nav-open'); navToggle.classList.remove('toggle-active'); } }); }); // Contact Form Submission const contactForm = document.getElementById('contact-form'); const formMessages = document.getElementById('form-messages'); contactForm.addEventListener('submit', function(e) { e.preventDefault(); const formData = { name: contactForm.name.value, email: contactForm.email.value, message: contactForm.message.value }; // Simple validation if (!formData.name || !formData.email || !formData.message) { formMessages.textContent = 'Please fill in all fields.'; formMessages.style.color = 'red'; return; } // Simulate form submission // You can replace this with actual form submission using fetch or XMLHttpRequest setTimeout(() => { formMessages.textContent = 'Thank you! Your message has been sent.'; formMessages.style.color = 'green'; contactForm.reset(); }, 1000); });Additional Notes
-
Images and Assets: Replace the placeholder image URL in the
.herosection with your own image to better suit your brand..hero { background: url('https://your-image-url.com/image.jpg') center center/cover no-repeat; /* ... */ } -
Responsive Navigation: The navigation menu is responsive. On screens smaller than 768px, a hamburger menu will appear. Clicking it toggles the navigation links.
-
Smooth Scrolling: Clicking on navigation links smoothly scrolls to the respective sections. This enhances user experience.
-
Contact Form: The contact form includes basic validation. For a production site, you'd want to implement proper backend form handling or integrate with a service like Formspree or EmailJS.
-
Customization: Feel free to modify the colors, fonts, and content to match your brand's identity.
How to Use
-
Create Files:
- Create a project folder.
- Inside the folder, create three files:
index.html,styles.css, andscript.js.
-
Add the Code:
- Copy the respective code snippets provided above into each file.
-
Run the Landing Page:
- Open
index.htmlin your web browser to see the landing page in action.
- Open
-
Deploy:
- Once you're satisfied, you can deploy your landing page using hosting services like GitHub Pages, Netlify, Vercel, etc.
Live Demo
For a quick preview, you can use CodePen or JSFiddle:
- CodePen: Create a new Pen and paste the HTML, CSS, and JavaScript code into their respective sections.
- JSFiddle: Similarly, create a new fiddle and allocate the code to HTML, CSS, and JavaScript panels.
This template provides a solid foundation for a landing page. You can expand upon it by adding more sections, animations, or integrating with backend services as needed.