How to Add Serverless Functions and Forms to a Netlify Site

October 14, 2026

A static site stops being static the moment you need to accept a form or call a third-party API. Netlify covers both without a separate backend: Functions run server code on demand, and Forms captures submissions with almost no setup.

What Are Netlify Functions?

They are AWS Lambda functions Netlify manages for you. You drop a JavaScript or TypeScript file in a netlify/functions folder, export a handler, and Netlify exposes it at /.netlify/functions/your-name. No servers, no deployment config.

How to Create Your First Function

  1. Create netlify/functions/hello.js.
  2. Export a handler that returns a status code and body.
  3. Push to your repo. Netlify deploys the function automatically.
  4. Call it from your front end with fetch('/.netlify/functions/hello').
  5. For scheduled work, add a cron-style schedule config to the function.

Cold starts on the free tier run 200-500 ms for Node functions. Warm invocations answer in tens of milliseconds.

How Do Netlify Forms Work?

Add a data-netlify="true" attribute to an HTML form and Netlify starts capturing submissions — no endpoint code required. You get a submissions dashboard, email or webhook notifications, and spam filtering. JavaScript-rendered forms need a hidden static copy of the form in the HTML so Netlify’s build bot can detect the fields.

Feature Free plan Pro plan
Form submissions 100/month 1,000/month
Functions 125K invocations 2M invocations

How Do You Secure a Function?

Never put secrets in front-end code. Use Netlify environment variables, which are available to functions at runtime via process.env. For endpoints that shouldn’t be public, check an auth header inside the function. Functions are public URLs by default — anyone can call them.

Where Do Functions Fall Short?

Execution time is capped (10 seconds on the free tier’s default, longer with configuration), so long-running jobs fail. They also don’t hold state between invocations. For background processing, use background functions on Pro or hand the job to a queue service.

Quick Summary

  • Netlify Functions are managed serverless endpoints, no config needed.
  • Add data-netlify="true" to a form to capture submissions instantly.
  • Free tier: 100 form submissions and 125K function calls monthly.
  • Store secrets in environment variables, never in front-end code.
  • Function timeouts make them unsuitable for long jobs.
Tags: