Modern Web App using HTMX (No JavaScript Required!)
- Get link
- X
- Other Apps
Demo :
Click Video πππ
HTMX + PHP: Modern Web App (No JavaScript Needed!)
π Folder Structure :
/modern-htmx-app
│── index.html
│── style.css
│── script.js (Minimal)
│── server.php
Code :
1️⃣ index.html (Main Web Page)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTMX Web App</title>
<link rel="stylesheet" href="style.css">
<script src="https://unpkg.com/htmx.org@1.9.5"></script>
</head>
<body>
<div class="container">
<h2>HTMX Web App - No JavaScript Required!</h2>
<!-- Input Form -->
<form id="dataForm" hx-post="server.php" hx-target="#response" hx-swap="innerHTML">
<input type="text" name="username" placeholder="Enter your name" required>
<button type="submit">Submit</button>
</form>
<!-- Response Area -->
<div id="response"></div>
</div>
</body>
</html>
2️⃣ style.css (Basic Styling)
body {
font-family: Arial, sans-serif;
text-align: center;
background: #f4f4f4;
padding: 50px;
}
.container {
max-width: 400px;
margin: auto;
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}
input {
width: 80%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ddd;
}
button {
background: #28a745;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
}
button:hover {
background: #218838;
}
3️⃣ server.php (Handles the Request)
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = htmlspecialchars($_POST["username"]);
echo "<h3>Welcome, $name!</h3>";
}
?>
4️⃣ script.js (Optional - Minimal JavaScript for Enhancements)
document.addEventListener("DOMContentLoaded", function () {
console.log("HTMX Web App Loaded!");
});
- Get link
- X
- Other Apps
Comments
Post a Comment