- LED Blink with Button
- Motion Detection Alarm System
- Simple RGB LED Controller
- Blinking LED with WebSocket Control
- Control LED Brightness using PWM
- Web Page with HTML and CSS on ESP32
- Control Multiple LEDs
- ESP32 with Bluetooth Serial Communication
- EEPROM with ESP32
- ESP32 Push Button Input: Reading Digital States
- Interfacing DHT11 Sensor
- Interfacing Ultrasonic Sensor
- Interfacing Flame Sensor
- Interfacing Sound Sensor
- Interfacing Potentiometer
- Interfacing IR Sensor
- Interfacing Servo Motor
- Interfacing Cam Wireless
- Interfacing DC Motor
- Interfacing Shock Sensor
- Interfacing Color Recognition Sensor
- Interfacing RFID Module
- TTGO LoRa32 SX1276 OLED
- Interfacing Keypad
- Interfacing Solenoid Lock
- Interfacing 16x2 LCD
- Interfacing Soil Moisture
- Interfacing MQ-7 Gas Sensor
- Interfacing Light Sleep Mode
- Interfacing Smart Light Control
- Interfacing (IoT) Weather Station
- Interfacing Web Server for Temperature Data Display
- Interfacing Home Automation System with Relay Control
- Interfacing IoT Smart Garden
- Face Recognition-Based Door Unlock System
- Interfacing Wi-Fi Jammer Detector
- Interfacing Health Band with Pulse
- Interfacing Sound Level Logger for Classrooms
- Night Vision Surveillance Camera
- Solar Panel Monitoring System
- Smart Farming Robot for Crop Surveillance
- Smart Water Quality Monitoring System
- Industrial IoT Gateway for Real-Time Monitoring
- Agriculture System with Automated Drone Control
Create a Web Page with HTML and CSS on ESP32
What is a Web Page on ESP32?
The ESP32 can function as a web server, serving HTML, CSS, and JavaScript files over Wi-Fi. This allows you to build user interfaces to interact with sensors, control devices, and visualize data — all from your browser. Hosting a webpage on the ESP32 makes it a powerful platform for smart IoT dashboards.
Working Principle of ESP32 Web Server
The ESP32 connects to a Wi-Fi network and sets up an HTTP server. When a client (browser) requests a URL, the ESP32 responds by sending HTML and CSS content. The webpage is displayed on the user's device, allowing interactive control or monitoring.
- Connect ESP32 to Wi-Fi.
- Initialize a web server using ESPAsyncWebServer or WebServer library.
- Store HTML and CSS in variables or files.
- Serve content via HTTP responses.
- Access webpage by visiting ESP32's IP in a browser.
Formula: N/A
Components Required
- ESP32 development board
- Micro USB cable
- Wi-Fi network
- Laptop or smartphone
Pin Configuration
- N/A: This experiment does not use GPIOs for hardware interfacing.
Ensure that both the ESP32 and your browser device are connected to the same Wi-Fi network to access the web page.
Wi-Fi Setup and Configuration
- Wi-Fi SSID -> Enter your network SSID in code
- Wi-Fi Password -> Enter your Wi-Fi password in code
Arduino Code to Serve HTML and CSS Web Page
1#include <WiFi.h>
2#include <WebServer.h>
3
4const char* ssid = "YOUR_SSID";
5const char* password = "YOUR_PASSWORD";
6
7WebServer server(80);
8
9const char* htmlPage = R"rawliteral(
10<!DOCTYPE html>
11<html>
12<head>
13 <title>ESP32 Web Page</title>
14 <style>
15 body { background-color: #f0f0f0; font-family: Arial; text-align: center; padding: 50px; }
16 h1 { color: #333; }
17 button { padding: 10px 20px; font-size: 16px; }
18 </style>
19</head>
20<body>
21 <h1>Hello from ESP32!</h1>
22 <p>This web page is hosted on your ESP32</p>
23 <button onclick="alert('Button clicked!')">Click Me</button>
24</body>
25</html>
26)rawliteral";
27
28void setup() {
29 Serial.begin(115200);
30 WiFi.begin(ssid, password);
31 while (WiFi.status() != WL_CONNECTED) {
32 delay(1000);
33 Serial.println("Connecting to WiFi...");
34 }
35 Serial.println("Connected!");
36 Serial.println(WiFi.localIP());
37
38 server.on("/", []() {
39 server.send(200, "text/html", htmlPage);
40 });
41 server.begin();
42 Serial.println("Web server started.");
43}
44
45void loop() {
46 server.handleClient();
47}
Code Explanation (Line-by-Line)
- #include <WiFi.h>: Includes the Wi-Fi library to connect ESP32 to a network.
- #include <WebServer.h>: Includes the library to create a basic web server.
- const char* htmlPage = R"rawliteral(...)";: Stores the HTML and CSS content as a raw string literal.
- WiFi.begin(ssid, password);: Connects ESP32 to the specified Wi-Fi network.
- server.on("/", []() {...});: Defines a route that serves the webpage on root path '/'.
- server.send(200, "text/html", htmlPage);: Sends HTML content with a 200 OK HTTP response.
- server.handleClient();: Handles incoming HTTP client requests in the main loop.
Applications
- Remote sensor dashboards
- Controlling devices from browser
- IoT UI development
- Smart home control panels
- Educational demos and prototypes
Conclusion
Creating a web page using HTML and CSS on ESP32 allows you to build fully functional IoT dashboards. It enables remote interaction with sensors or devices through a browser, making ESP32 a flexible and powerful tool for web-based IoT solutions.