DEV Community

Cover image for How to Build a Responsive Landing Page with HTML, CSS, and JS
Shevin Nikesh
Shevin Nikesh

Posted on

How to Build a Responsive Landing Page with HTML, CSS, and JS

1. Setting Up the Project
Start by creating your project folder with the following structure:

landing-page/
  ├── index.html
  ├── styles.css
  ├── script.js
Enter fullscreen mode Exit fullscreen mode

HTML: The Structure

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Responsive Landing Page</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <header class="navbar">
    <nav>
      <h1 class="logo">MyBrand</h1>
      <ul class="nav-links">
        <li><a href="#features">Features</a></li>
        <li><a href="#pricing">Pricing</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </nav>
  </header>

  <section class="hero">
    <div class="hero-content">
      <h2>Build Modern Websites</h2>
      <p>Responsive designs that captivate your audience.</p>
      <button>Get Started</button>
    </div>
    <img src="hero-image.jpg" alt="Hero Image">
  </section>

  <section id="features">
    <h2>Features</h2>
    <p>Highlight your product's features here.</p>
  </section>

  <section id="pricing">
    <h2>Pricing</h2>
    <p>Affordable plans for everyone.</p>
  </section>

  <section id="contact">
    <h2>Contact Us</h2>
    <form>
      <input type="email" placeholder="Your Email">
      <button type="submit">Submit</button>
    </form>
  </section>

  <footer>
    <p>&copy; 2024 MyB
rand. All Rights Reserved.</p>
  </footer>

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

Enter fullscreen mode Exit fullscreen mode

2. Styling with CSS

/* General Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  line-height: 1.6;
}

/* Navbar */
.navbar {
  background: #4A00E0;
  color: #fff;
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-links {
  list-style: none;
  display: flex;
}

.nav-links li {
  margin-left: 20px;
}

.nav-links a {
  color: #fff;
  text-decoration: none;
}

/* Hero Section */
.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 40px;
  background: linear-gradient(135deg, #8E2DE2, #4A00E0);
  color: #fff;
}

.hero-content h2 {
  font-size: 2.5rem;
}

.hero img {
  width: 40%;
}

/* Responsive Design */
@media (max-width: 768px) {
  .hero {
    flex-direction: column;
    text-align: center;
  }

  .hero img {
    width: 80%;
  }
}

Enter fullscreen mode Exit fullscreen mode

3. Enhancing with JavaScript

// script.js
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
  anchor.addEventListener("click", function(e) {
    e.preventDefault();
    document.querySelector(this.getAttribute("href")).scrollIntoView({
      behavior: "smooth"
    });
  });
});

**4. Responsive and Engaging Design**
To make your landing page responsive:

Use flexbox and media queries for layouts.
Optimize images for different screen sizes.
Test responsiveness using browser developer tools.
5. Optional: Adding Animations
For modern aesthetics, use CSS animations.

Enter fullscreen mode Exit fullscreen mode
Optional: Adding Animations
Enter fullscreen mode Exit fullscreen mode

/* Button Hover */
button {
background: #fff;
color: #4A00E0;
border: none;
padding: 10px 20px;
cursor: pointer;
transition: all 0.3s ease-in-out;
}

button:hover {
background: #4A00E0;
color: #fff;
}

Final Thoughts
Building a responsive landing page requires balancing design, performance, and user experience. By using HTML, CSS, and JavaScript effectively, you can create a page that is visually appealing and functional.

What are your thoughts? Share your customizations and tips in the comments below! 😊

Top comments (0)