It is the first time I try do this. I configured HTML file and it was served.

I want to give style to my HTML form with internal or external CSS, but I can't. However, I used different tutorials I didn't manage to understand how to make it use the CSS.

I have a main directory and index.h, style.css and main.ino files in it. Here is my code. Can anybody show me what is the correct code?

#include <WiFiClient.h>
#include <ESP8266WebServer.h>

#include "index.h"
//#include "style.h"

//SSID and Password to your ESP Access Point
const char* cssfile = "style.css";
const char* ssid = "ESPWebServer";
const char* password = "12345678";

ESP8266WebServer server(80); //Server on port 80

//     This rutine is exicuted when you open its IP in browser
String s = MAIN_page;
//String sx = MAIN_STYLE;
void handleRoot() {
  server.send(200, "text/html", s);
  server.send(800, "text/css", "");

//                  SETUP
void setup(void){
  WiFi.mode(WIFI_AP);           //Only Access point
  WiFi.softAP(ssid);  //Start HOTspot removing password will disable security
  IPAddress myIP = WiFi.softAPIP(); //Get IP address
Serial.print("HotSpt IP:");

  server.on("/", handleRoot);      //Which routine to handle at root location

  server.begin();                  //Start server
  Serial.println("HTTP server started");
//                     LOOP
void loop(void){
  server.handleClient();          //Handle client requests

bool loadFromSpiffs(String path){
  String dataType = "text/plain";
  if(path.endsWith("/")) path += "index.htm";

  if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
  else if(path.endsWith(".html")) dataType = "text/html";
  else if(path.endsWith(".css")) dataType = "text/css";

  return true;
  • see the AdvancedWebServer example – Juraj Feb 11 at 10:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.