ESP32 LittleFS Tutorial: File Storage, Read/Write & Web Server with Arduino IDE

ESP32 LittleFS Tutorial: File Storage, Read/Write & Web Server with Arduino IDE

Oct 15th, 2026

ESP32 LittleFS tutorial showing an ESP32 board, file storage, read/write operations, and a web server displayed on a laptop.

An ESP32 normally keeps variables in RAM while a program is running. That works well for temporary data, but unlike ESP32 flash memory, RAM loses its contents when the board restarts or loses power.

Some projects need information to remain available between restarts. An ESP32 file system can preserve Wi-Fi configurations, device settings, calibration values, HTML pages, and log files when the board is powered off.

For this type of data, the ESP32 can use part of its flash memory as a filesystem.ESP32 LittleFS provides a convenient way to create, read, update, organize, and delete files stored directly in flash memory.

This tutorial explains how LittleFS works with the Arduino IDE and shows the main file operations through practical examples.

Why an ESP32 Sometimes Needs Local File Storage

Consider an ESP32 that connects to a Wi-Fi network. Hard-coding the SSID and password inside the sketch works during development, but it becomes inconvenient if the network changes.
Instead, the ESP32 can use LittleFS to store these settings in a file.

Local storage is also useful for:
•Device configuration
•Sensor calibration data
•HTML, CSS, and JavaScript files
•Small logs
•User preferences
•Data that must survive a restart

For ESP32 file storage, the important distinction is between RAM and flash memory.
On the ESP32, RAM acts as fast working memory. Variables created while the program runs normally live there, but their contents disappear after a reset.
Flash is non-volatile memory. It contains the ESP32 firmware and can also reserve an area for persistent data. LittleFS uses this flash area to provide file-based storage. For a closer look at different types of ESP32 memory, read our ESP32 flash and RAM guide.

What Is LittleFS?

The LittleFS filesystem is designed for lightweight, flash-based storage in ESP32 flash memory.

Instead of handling raw flash memory addresses, the ESP32 file system provided by LittleFS lets Arduino sketches access familiar files and paths such as:
/config.txt
/index.html
/settings/device.txt


With LittleFS, an ESP32 program can open these files, write information to them, read their contents later, rename them, or remove them.

Flash Filesystem

LittleFS stores its data in a filesystem partition inside the ESP32 flash memory. The exact amount of available space depends on the board and partition configuration.

Files and Directories

LittleFS files can be organized using paths, making larger ESP32 projects easier to maintain. A web server, for example, might use:
/www/index.html
/www/style.css
/config/network.txt

Persistent Storage

Files stored with ESP32 LittleFS remain in flash after a reset or power cycle unless they are explicitly deleted, overwritten, the filesystem is formatted, or the relevant flash partition is erased.

LittleFS vs SPIFFS vs SD Card

When comparing LittleFS vs SPIFFS vs SD card storage, all three provide file storage but serve slightly different needs.

FeatureLittleFSSPIFFSSD Card
Storage locationInternal flashInternal flashExternal card
Typical capacityLimited by flash partitionLimited by flash partitionUsually much larger
External hardwareNoNoYes
Directory supportYesLimited filesystem behaviorYes
Reliability for embedded filesGoodOlder optionDepends on card/hardware
Best useConfigs, web assets, small filesExisting legacy projectsLogs, images, large datasets

For a new ESP32 project that needs relatively small files stored internally, LittleFS is usually a practical choice. An SD card becomes more appropriate when the project needs significantly more storage or frequently handles large files; see our ESP32 SD card guide for setup and storage examples.

When to Use LittleFS

ESP32 LittleFS works particularly well when a project needs a modest amount of persistent local storage without adding hardware.

Typical applications include configuration portals, local web servers, saved network settings, calibration files, certificates, and small data files.

ESP32 LittleFS is less suitable for continuously recording large amounts of sensor data. An SD card, database, or remote storage system may be a better option in those situations.

ESP32 Flash Partitions and LittleFS

ESP32 flash memory is not normally used as one large storage area.Instead, flash is divided into partitions, with each partition reserved for a particular purpose.

Depending on the selected configuration, these partitions can include:
•Application (App): Stores the program uploaded to the ESP32.
•OTA: Provides space for firmware updates without connecting the board to a computer.
•NVS: Stores small persistent values used by the system or application, such as settings and Wi-Fi-related data.
•Filesystem: Reserves flash space for a filesystem such as LittleFS.

This means that an ESP32 with 4 MB of flash memory does not have 4 MB available for LittleFS file storage. Part of that flash must contain the application and other required data. LittleFS can only use the space assigned to its filesystem partition.

The partition scheme determines how the available flash is divided; Espressif's partition table documentation explains how these partitions are defined.A scheme that reserves more space for the application may leave less space for LittleFS. Another scheme may provide a larger filesystem but reduce the maximum application size or change the space available for OTA updates.

For example, the basic idea can be represented as:

ESP32 flash memory partition layout showing NVS, application firmware, OTA, and LittleFS filesystem storage.

The exact sizes depend on the ESP32 board, its flash capacity, the ESP32 Arduino core, and the partition scheme selected.

Choosing a Partition Scheme in Arduino IDE

For supported ESP32 board configurations, partition options can be selected in the Arduino IDE from the menu below. If you need help setting up the board first, see our ESP32 Arduino IDE setup guide.

Tools → Partition Scheme
The available choices vary depending on the selected board.

When choosing a scheme, consider what the project needs.A simple ESP32 LittleFS configuration project may require only a small filesystem partition, while an ESP32 web server containing multiple HTML, CSS, JavaScript, and image files may benefit from more filesystem space.

The important point is to check the partition layout rather than assuming that the board's total flash capacity is available for file storage.

After LittleFS is mounted, the sketch can check the actual filesystem capacity with:

Serial.printf("LittleFS total: %u bytes\n", LittleFS.totalBytes());
Serial.printf("LittleFS used: %u bytes\n", LittleFS.usedBytes());

This provides a practical way to confirm how much ESP32 flash memory the selected partition scheme has made available to LittleFS.

Setting Up LittleFS in Arduino IDE

With a current ESP32 Arduino core installed, you can include LittleFS directly in an Arduino IDE sketch:

In ESP32 LittleFS, the true argument allows the filesystem to be formatted if mounting fails.This is convenient during development, although automatic formatting should be considered carefully when the device contains important data.

Basic LittleFS Operations

•Mount the Filesystem
LittleFS.begin();
Mounting makes the filesystem available to the program.

•Create and Write a File
When writing files with ESP32 LittleFS, opening a nonexistent file with FILE_WRITE creates it.
File file = LittleFS.open("/message.txt", FILE_WRITE);
if (file) {
  file.println("Hello from ESP32");
  file.close();
}

•Append Data
Use FILE_APPEND when existing contents should be preserved:
File file = LittleFS.open("/message.txt", FILE_APPEND);
 if (file) {
  file.println("New line");
  file.close();
}

•Read a File File
file = LittleFS.open("/message.txt", FILE_READ);
if (file) {
  while (file.available()) {
    Serial.write(file.read());
  }
  file.close();
}

•Rename a File
LittleFS.rename("/message.txt", "/data.txt");

•Delete a File
LittleFS.remove("/data.txt");
When using ESP32 LittleFS, always close files after using them so resources are released correctly.

Arduino Example: Save and Read a Configuration File

One of the main advantages of LittleFS is that files remain stored in flash memory even after the ESP32 restarts or loses power.

In this ESP32 LittleFS example, the program checks whether a configuration file already exists.If the file is missing, it creates one with default settings. If the file already exists, the ESP32 keeps its contents unchanged and reads the saved configuration.

Using LittleFS on the ESP32 is useful for storing device names, sensor intervals, network settings, and other information that should persist between restarts.

Initializing LittleFS for the First Time
Before running the configuration file example, make sure the ESP32's LittleFS partition has been initialized.
On a new or unformatted filesystem partition, LittleFS.begin(false) may fail because no valid LittleFS filesystem exists yet.
To initialize ESP32 LittleFS for the first time, upload and run the following Arduino sketch:

How to Use This Sketch
1.Connect your ESP32 to the computer.
2.Select the correct board, serial port, and partition scheme in Arduino IDE.
3.Upload the initialization sketch.
4.Open the Serial Monitor at 115200 baud.
5.Wait for the initialization result.

If the filesystem is already initialized, you should see:
Initializing LittleFS...
LittleFS is already initialized.
If the filesystem was unformatted and initialization succeeds, you should see:
Initializing LittleFS...
Mount failed. Formatting LittleFS...
LittleFS initialized successfully!

Once ESP32 LittleFS initialization is complete, upload the main configuration file example from the next section.
The main example uses LittleFS.begin(false) to mount the filesystem without automatically formatting it. It then creates /config.txt only if the file does not already exist.

This LittleFS setup allows the saved configuration to remain unchanged across ESP32 restarts and power cycles.

Important: Formatting erases existing files in the LittleFS partition. A mount failure does not necessarily mean the filesystem is empty; it may also indicate incorrect partition settings or filesystem corruption. Only run this initialization sketch when you are certain that no important data needs to be preserved.

For deployed devices, avoid automatically formatting LittleFS after a mount failure.

Complete Arduino Code

How the Code Works
The sketch follows three simple steps:
1.Mount LittleFS: LittleFS.begin(false) initializes the filesystem without automatically formatting it if mounting fails.
2.Check for an existing file: LittleFS.exists() determines whether /config.txt is already stored in flash. Default settings are written only when the file does not exist.
3.Read the configuration: The ESP32 opens the file using FILE_READ and displays its contents in the Serial Monitor.

With LittleFS, the ESP32 recognizes the existing configuration file and reads its contents without overwriting them.

Testing persistence: To verify that the saved configuration is preserved, change the file contents using a separate sketch or file-editing routine, then restart the ESP32.The modified values should remain unchanged.

This demonstrates how LittleFS can retain configuration data across restarts and power cycles without requiring an SD card or external storage device.

Important: The example assumes that the LittleFS partition has already been initialized with a valid filesystem. If mounting fails on a new or unformatted partition, it must first be formatted or initialized. Avoid automatic formatting on deployed devices containing important files.

Working with Directories

LittleFS directories help keep ESP32 projects organized.
Create a directory with:
LittleFS.mkdir("/config");
A file can then be stored inside it:
File file = LittleFS.open("/config/device.txt", FILE_WRITE);
file.println("ESP32");
file.close();

Remove an empty directory with:
LittleFS.rmdir("/config");
For an ESP32 LittleFS web-server project, separating configuration files from web assets can make the filesystem much easier to maintain.

Project Example: Store a Web Page in LittleFS

One useful ESP32 LittleFS web server application is storing a web page separately from the Arduino sketch.

ESP32 LittleFS web server diagram showing how an ESP32 reads index.html from flash memory and sends the HTML page to a browser.

Instead of placing a large HTML document inside a C++ string, the ESP32 reads /index.html from LittleFS and sends it to the browser.
For example:

Serving files with ESP32 LittleFS keeps the firmware cleaner and makes web projects easier to organize.CSS, JavaScript, images, and other assets can also be stored as separate files.

The exact server code depends on the web-server library being used, but the storage principle remains the same: the browser requests a resource, the ESP32 web server handles the request, and the required file is retrieved from LittleFS.

Step 1: Create the Project Files
To build the ESP32 LittleFS web server, create a new Arduino sketch named ESP32_LittleFS_WebServer and add a folder called data inside the sketch directory.

The data folder contains the web files that will be uploaded to the ESP32 LittleFS partition.

ESP32 LittleFS web server project folder showing the data directory and ESP32_LittleFS_WebServer.ino Arduino sketch.

Step 2: Create the HTML File
For this ESP32 LittleFS web server, create index.html inside the data folder and paste the following code:

This page includes basic HTML and CSS. Both are stored in the same file to keep the example simple.
Step 3: Write the ESP32 Arduino Code
Open ESP32_LittleFS_WebServer.ino and enter the following code:

Replace YOUR_WIFI_SSID and YOUR_WIFI_PASSWORD with the credentials of your Wi-Fi network. The ESP32 and the device opening the page must be able to communicate over the local network.

The code uses LittleFS.begin(false) to mount the filesystem without automatically formatting it if mounting fails. This helps avoid accidentally erasing uploaded files.

Step 4: Upload the LittleFS Files
Before running the ESP32 LittleFS web server, we need to upload the index.html file to the ESP32's LittleFS filesystem.
Unlike uploading an Arduino sketch, uploading files to LittleFS requires a filesystem uploader tool.

1. Install the LittleFS Uploader Plugin
For Arduino IDE 2.2.1 or later, download the latest .vsix file from the Arduino LittleFS Upload plugin releases page.Download the latest .vsix file from:
https://github.com/earlephilhower/arduino-littlefs-upload/releases
Close Arduino IDE and copy the downloaded .vsix file into the following directory:
Windows: C:\Users\<username>\.arduinoIDE\plugins\
macOS / Linux: ~/.arduinoIDE/plugins/
Create the plugins folder if it does not already exist. Keep the downloaded file in .vsix format; there is no need to extract it.
Restart Arduino IDE to activate the plugin.

2. Prepare the Project Files
Open the ESP32_LittleFS_WebServer sketch created earlier.
Go to Sketch → Show Sketch Folder and confirm that your project has the following structure:
ESP32_LittleFS_WebServer/
├── ESP32_LittleFS_WebServer.ino
└── data/
    └── index.html
The data folder must be located in the same sketch directory as the .ino file.
The LittleFS uploader packages the files inside this folder into a filesystem image and uploads it to the ESP32 LittleFS partition.

3. Select the ESP32 Board and Partition Scheme
Connect your ESP32 to your computer using a USB data cable.
In Arduino IDE:
1.Go to Tools → Board and select your ESP32 board.
2.Go to Tools → Port and select the correct serial port.
3.Go to Tools → Partition Scheme and choose a scheme that provides a filesystem partition.
The available partition schemes depend on your ESP32 board and its flash capacity.
Make sure the selected scheme provides enough filesystem space for index.html.

4. Upload the Files to LittleFS
Close the Serial Monitor before uploading, as it may prevent the uploader from accessing the serial port.
Open the Arduino IDE Command Palette:
Windows / Linux: Press Ctrl + Shift + P
macOS: Press Command + Shift + P

Search for and select:
Upload LittleFS to Pico/ESP8266/ESP32
The plugin will create a LittleFS filesystem image from the data folder and upload it to the ESP32 flash memory.
Wait until the upload process finishes successfully.
Note: The LittleFS upload command is accessed through the Command Palette in Arduino IDE 2.x, not through the Tools menu.

5. Upload the Arduino Sketch
After the LittleFS files have been uploaded successfully, upload the ESP32_LittleFS_WebServer.ino sketch using the normal Arduino IDE Upload button.
Open the Serial Monitor and set the baud rate to 115200.
After connecting to Wi-Fi, the ESP32 should display its local IP address.
Open a browser on a computer or smartphone that can access the same local network, and enter the displayed IP address.

You should see the web page stored in LittleFS, displaying:
ESP32 Web Server
Welcome to your ESP32!
This page is stored in LittleFS flash memory.
No external SD card is required.
This confirms that the ESP32 can successfully read index.html from LittleFS and serve it through the web server.
Important: An ESP32 LittleFS file upload may replace existing files in the target filesystem partition. Back up any important stored data before uploading.

Checking Used and Available Flash Space

LittleFS can report filesystem capacity:
Serial.printf("Total: %u bytes\n", LittleFS.totalBytes());
Serial.printf("Used: %u bytes\n", LittleFS.usedBytes());

Available filesystem space can be calculated with:
size_t freeBytes =
    LittleFS.totalBytes() - LittleFS.usedBytes();
Serial.printf("Free: %u bytes\n", freeBytes);

Checking ESP32 LittleFS storage space is useful when storing logs or files that can grow over time.

LittleFS and Flash Wear

Flash memory has a limited number of program/erase cycles. LittleFS is designed with flash storage in mind and uses techniques that help distribute filesystem updates.
That does not mean writes are unlimited.
When using ESP32 LittleFS, avoid rewriting a file unnecessarily inside a fast loop(). If a sensor value changes every few milliseconds, writing every measurement to flash is usually a poor design.
Instead, reduce LittleFS writes by saving information only when necessary, buffering data in RAM, or writing at controlled intervals.

Common LittleFS Problems

A failed mount is one of the most common problems. Check that the board configuration provides a suitable filesystem partition and that initialization succeeds before opening files.
Another common ESP32 LittleFS issue is using incorrect file paths.Keeping paths consistent and starting them with / avoids unnecessary confusion.
If a file cannot be opened, always test the returned File object:
File file = LittleFS.open("/config.txt", FILE_READ);
if (!file) {
  Serial.println("File open failed");
}

Also remember that formatting the filesystem removes stored files. Automatically formatting after a mount failure may be useful during development but can destroy valuable configuration data on a deployed device.

LittleFS Best Practices

Keep the ESP32 LittleFS filesystem organized with clear filenames and directory structures.Check whether mounting and file operations succeed instead of assuming they worked.

Close files after reading or writing, avoid excessive flash writes, and monitor free space when files can grow.

Use LittleFS for the job it handles best: relatively small, persistent files that belong with the ESP32 itself.

For configuration files, web assets, calibration information, and other embedded resources, LittleFS provides a simple bridge between raw flash memory and the familiar file-based storage model used on larger computers.

Conclusion

In this ESP32 LittleFS Tutorial, you learned how to use Arduino IDE to store, read, write, and manage files directly in ESP32 flash memory without an external SD card. We explored how LittleFS works, why choosing the right partition scheme matters, and how to initialize the filesystem safely. Through practical examples, you learned how to save and retrieve configuration data that persists across restarts and how to build an ESP32 Web Server that serves an HTML page stored in LittleFS. You also learned how to upload files to the ESP32 filesystem using Arduino IDE. With these skills, you can use LittleFS in future ESP32 projects to manage device settings, store web interface files, and organize data more efficiently.

Frequently Asked Questions (FAQ)

1. Why does LittleFS.begin(false) fail on my ESP32?
LittleFS.begin(false) may fail if the filesystem partition has not been formatted, the partition scheme is incorrect, or the filesystem is corrupted.
For a new ESP32 LittleFS project, verify that the selected partition scheme includes a compatible filesystem partition.If the partition is unformatted, initialize LittleFS before running the main program.
Important: Do not automatically format the filesystem whenever mounting fails, because formatting can permanently erase existing files.

2. What is the difference between LittleFS.begin(true) and LittleFS.begin(false)?
The parameter controls whether LittleFS is allowed to format the filesystem if mounting fails.
LittleFS.begin(true) allows automatic formatting after a mount failure.
LittleFS.begin(false) attempts to mount the existing filesystem without automatically formatting it.
For applications that store important configuration files or user data, LittleFS.begin(false) is generally the safer option. Use formatting only when you intentionally want to initialize or reset the filesystem.

3. How do I upload HTML files to ESP32 LittleFS using Arduino IDE?
For ESP32 LittleFS file uploads in Arduino IDE 2.x, you can use a compatible LittleFS uploader plugin.
Create a data folder inside your Arduino sketch directory and place files such as index.html inside it.
After installing the uploader plugin, connect your ESP32, select the correct board, port, and partition scheme, and open the Command Palette using Ctrl + Shift + P (Windows/Linux) or Command + Shift + P (macOS).
Search for the LittleFS upload command and run it to upload the contents of the data folder to the ESP32's filesystem partition.

4. Why can't my ESP32 Web Server find index.html?
If your ESP32 LittleFS web server cannot load index.html, check the following:
Make sure index.html is located inside the sketch's data folder.
Confirm that the LittleFS filesystem image was uploaded successfully.
Verify that the Arduino code uses the correct file path, such as /index.html.
Make sure LittleFS mounts successfully before the web server attempts to read the file.
Confirm that the selected partition scheme is compatible with your filesystem image.
Remember that uploading an Arduino sketch does not automatically upload the files inside the data folder.

5. Does uploading new Arduino code erase LittleFS files?
Normally, uploading a new ESP32 Arduino sketch does not erase the LittleFS filesystem partition if the partition layout remains unchanged and the upload process does not perform a full flash erase.
However, changing the partition scheme, performing a full flash erase, or uploading a new filesystem image may affect stored files.
Back up important LittleFS data before changing ESP32 flash partition settings or performing filesystem operations.

Back to News ESP32 MQTT Tutorial: Publish Sensor Data and Control an LED