HTML Examples & Templates

Explore ready-to-use HTML examples and templates. Copy any example and paste it into our HTML viewer to see it in action.

Basic HTML Document

A simple HTML document structure with basic elements

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Basic HTML</title>
</head>
<body>
    <h1>Hello World!</h1>
    <p>This is a basic HTML document.</p>
</body>
</html>

Styled Card Component

A modern card component with CSS styling

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Card Component</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background: #f0f2f5;
            margin: 0;
            padding: 20px;
        }
        .card {
            background: white;
            border-radius: 12px;
            padding: 24px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            max-width: 400px;
            margin: 0 auto;
        }
        .card h2 {
            color: #333;
            margin-top: 0;
        }
        .card p {
            color: #666;
            line-height: 1.6;
        }
        .button {
            background: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 6px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="card">
        <h2>Card Title</h2>
        <p>This is a beautiful card component with modern styling.</p>
        <button class="button">Learn More</button>
    </div>
</body>
</html>

Responsive Grid Layout

A responsive grid layout using CSS Grid

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Grid Layout</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background: #f8f9fa;
        }
        .grid-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            max-width: 1200px;
            margin: 0 auto;
        }
        .grid-item {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .grid-item h3 {
            margin-top: 0;
            color: #333;
        }
        .grid-item p {
            color: #666;
        }
    </style>
</head>
<body>
    <h1 style="text-align: center; color: #333;">Responsive Grid Layout</h1>
    <div class="grid-container">
        <div class="grid-item">
            <h3>Item 1</h3>
            <p>This is the first grid item with some content.</p>
        </div>
        <div class="grid-item">
            <h3>Item 2</h3>
            <p>This is the second grid item with different content.</p>
        </div>
        <div class="grid-item">
            <h3>Item 3</h3>
            <p>This is the third grid item in our responsive grid.</p>
        </div>
        <div class="grid-item">
            <h3>Item 4</h3>
            <p>This is the fourth grid item that adapts to screen size.</p>
        </div>
    </div>
</body>
</html>

Navigation Menu

A horizontal navigation menu with hover effects

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Navigation Menu</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            background: #f5f5f5;
        }
        .navbar {
            background: #333;
            padding: 0;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .nav-list {
            list-style: none;
            margin: 0;
            padding: 0;
            display: flex;
        }
        .nav-item {
            margin: 0;
        }
        .nav-link {
            display: block;
            color: white;
            text-decoration: none;
            padding: 15px 20px;
            transition: background-color 0.3s;
        }
        .nav-link:hover {
            background: #555;
        }
        .content {
            padding: 40px 20px;
            text-align: center;
        }
    </style>
</head>
<body>
    <nav class="navbar">
        <ul class="nav-list">
            <li class="nav-item"><a href="#" class="nav-link">Home</a></li>
            <li class="nav-item"><a href="#" class="nav-link">About</a></li>
            <li class="nav-item"><a href="#" class="nav-link">Services</a></li>
            <li class="nav-item"><a href="#" class="nav-link">Contact</a></li>
        </ul>
    </nav>
    <div class="content">
        <h1>Welcome to Our Website</h1>
        <p>This is a sample page with a navigation menu.</p>
    </div>
</body>
</html>

Form with Styling

A contact form with modern CSS styling

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact Form</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            margin: 0;
            padding: 20px;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .form-container {
            background: white;
            padding: 40px;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
            width: 100%;
            max-width: 400px;
        }
        .form-container h2 {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #555;
            font-weight: bold;
        }
        .form-group input,
        .form-group textarea {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            transition: border-color 0.3s;
            box-sizing: border-box;
        }
        .form-group input:focus,
        .form-group textarea:focus {
            outline: none;
            border-color: #667eea;
        }
        .submit-btn {
            width: 100%;
            background: #667eea;
            color: white;
            border: none;
            padding: 15px;
            border-radius: 6px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .submit-btn:hover {
            background: #5a6fd8;
        }
    </style>
</head>
<body>
    <div class="form-container">
        <h2>Contact Us</h2>
        <form>
            <div class="form-group">
                <label for="name">Name</label>
                <input type="text" id="name" name="name" required>
            </div>
            <div class="form-group">
                <label for="email">Email</label>
                <input type="email" id="email" name="email" required>
            </div>
            <div class="form-group">
                <label for="message">Message</label>
                <textarea id="message" name="message" rows="5" required></textarea>
            </div>
            <button type="submit" class="submit-btn">Send Message</button>
        </form>
    </div>
</body>
</html>

Image Gallery

A responsive image gallery with hover effects

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image Gallery</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background: #f8f9fa;
        }
        .gallery-title {
            text-align: center;
            color: #333;
            margin-bottom: 40px;
        }
        .gallery {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            max-width: 1200px;
            margin: 0 auto;
        }
        .gallery-item {
            position: relative;
            overflow: hidden;
            border-radius: 12px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            transition: transform 0.3s ease;
        }
        .gallery-item:hover {
            transform: translateY(-5px);
        }
        .gallery-item img {
            width: 100%;
            height: 200px;
            object-fit: cover;
            display: block;
        }
        .gallery-overlay {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            background: linear-gradient(transparent, rgba(0,0,0,0.7));
            color: white;
            padding: 20px;
            transform: translateY(100%);
            transition: transform 0.3s ease;
        }
        .gallery-item:hover .gallery-overlay {
            transform: translateY(0);
        }
        .gallery-overlay h3 {
            margin: 0 0 5px 0;
            font-size: 18px;
        }
        .gallery-overlay p {
            margin: 0;
            font-size: 14px;
            opacity: 0.9;
        }
    </style>
</head>
<body>
    <h1 class="gallery-title">Photo Gallery</h1>
    <div class="gallery">
        <div class="gallery-item">
            <img src="/placeholder.svg?height=200&width=300" alt="Mountain Landscape">
            <div class="gallery-overlay">
                <h3>Mountain View</h3>
                <p>Beautiful mountain landscape at sunset</p>
            </div>
        </div>
        <div class="gallery-item">
            <img src="/placeholder.svg?height=200&width=300" alt="Ocean Waves">
            <div class="gallery-overlay">
                <h3>Ocean Waves</h3>
                <p>Peaceful ocean waves on a sunny day</p>
            </div>
        </div>
        <div class="gallery-item">
            <img src="/placeholder.svg?height=200&width=300" alt="Forest">
            <div class="gallery-overlay">
                <h3>Forest Path</h3>
                <p>A winding path through the forest</p>
            </div>
        </div>
        <div class="gallery-item">
            <img src="/placeholder.svg?height=200&width=300" alt="City Skyline">
            <div class="gallery-overlay">
                <h3>City Lights</h3>
                <p>Urban skyline illuminated at night</p>
            </div>
        </div>
    </div>
</body>
</html>

How to Use These Examples

  1. Click "Copy Code" on any example above
  2. Go back to our HTML viewer
  3. Paste the code into the HTML input area
  4. See the live preview instantly
  5. Modify the code to customize it for your needs

Learning Tips

  • • Start with basic examples and gradually try more complex ones
  • • Experiment with colors, fonts, and spacing
  • • Try combining elements from different examples
  • • Use browser developer tools to inspect the rendered HTML

Best Practices

  • • Always include proper DOCTYPE and meta tags
  • • Use semantic HTML elements for better accessibility
  • • Keep CSS organized and use meaningful class names
  • • Test your HTML on different screen sizes