splitforms.com

HTML · ELEMENT

HTML legend Element: Caption a Fieldset (Radio and Checkbox Groups)

Last reviewed

The <legend> element is the caption of a `<fieldset>`. It must be the **first child** of the fieldset, or browsers do not treat it as the caption. Screen readers use the legend as the name of the group, so a question like "Preferred contact method" is read out together with each radio button or checkbox inside. By default it sits on the fieldset border, in a gap the browser cuts for it. The legend text is never sent with the form.

  • Live, editable example
  • Copy-paste snippet
  • Attributes & common mistakes
Live demo · nothing is sent

What gets submitted

Fill in the form above and press its button. The demo stops the request and lists every name=value pair the browser would send, plus the controls it leaves out.

With a free access key in the form, these fields land in your splitforms dashboard; access_key and botcheck are read by splitforms, not stored as lead data.

Edit the HTML and re-run it
Runs in a sandbox. Nothing is sent.

Minimal snippet

legend-example.html
<fieldset>
  <legend>Preferred contact method</legend>
  <label><input type="radio" name="contact_method" value="email"> Email</label>
  <label><input type="radio" name="contact_method" value="phone"> Phone</label>
</fieldset>

Copy-paste code

HTML Legend Element code you can paste today.

Replace YOUR_ACCESS_KEY with a key from your free splitforms dashboard. The form posts to one endpoint — submissions land in your inbox and dashboard with spam filtering built in.

Get free access key
legend.html
<form id="contact" action="https://splitforms.com/api/submit" method="POST">
  <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY">

  <label for="name">Name</label>
  <input type="text" id="name" name="name" autocomplete="name" required>

  <fieldset>
    <!-- The legend must be the first child of the fieldset -->
    <legend>Preferred contact method</legend>

    <input type="radio" id="contact-email" name="contact_method" value="email" checked>
    <label for="contact-email">Email</label>

    <input type="radio" id="contact-phone" name="contact_method" value="phone">
    <label for="contact-phone">Phone</label>

    <input type="radio" id="contact-sms" name="contact_method" value="sms">
    <label for="contact-sms">Text message</label>
  </fieldset>

  <button type="submit">Send</button>
  <!-- Sent: name and contact_method=email. The legend text is not sent. -->
</form>

<style>
  /* Reset: remove the default border, padding and min-width */
  fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

  /* Make the legend a normal block heading instead of a border notch */
  legend { float: left; width: 100%; padding: 0; font-weight: 600; margin-bottom: 0.5rem; }
  legend + * { clear: both; }
</style>

Comparison

When do I use legend, label or aria-labelledby?

Use <fieldset> with <legend> to name a **group** of controls, such as radio buttons or checkboxes that answer one question. Use <label> to name a **single** field. Use role="group" with aria-labelledby only when you cannot use a fieldset, for example inside a layout that a fieldset breaks.

When do I use legend, label or aria-labelledby?
NeedUseExample
Name one input<label for>Email address field
Name a radio group<fieldset> + <legend>Preferred contact method: Email / Phone / Text
Name a checkbox group<fieldset> + <legend>Topics you want: News / Offers / Updates
Name a group without a fieldsetrole="group" + aria-labelledbyA custom grid of toggles
Name a custom radio group widgetrole="radiogroup" + aria-labelledbyStar rating built from buttons

Sources: WHATWG HTML Standard: The legend element · W3C WAI: Grouping controls

Attributes · <legend>

Which attributes does the legend element support?

Only global attributes such as id and class. The legend gets its meaning from its place as the first child of a <fieldset>.

HTML Legend Element attributes and what each one does
AttributeWhat it doesDocs
alignObsolete. <legend> has no attributes of its own besides global ones such as id and class; position and style it with CSS instead.MDN
<fieldset disabled>Set on the parent fieldset, it disables every control inside so none are sent. The legend still shows, and controls inside the legend stay enabled.MDN

Common mistakes

HTML legend mistakes to avoid

Putting it in the wrong place, making it too long, and expecting it in the form data.

  1. It must be the first child of the fieldset

    If any element comes before it, or it is wrapped in a <div>, the browser does not use it as the caption: it loses the border notch and screen readers do not read it as the group name.

  2. Keep the legend short

    Some screen readers (for example JAWS) repeat the legend before every radio button or checkbox in the group. Write a short question such as "Preferred contact method" and put longer help text in a paragraph linked with aria-describedby.

  3. The legend text is not submitted

    Only named controls are sent. With the example above the POST body has contact_method=email, never the words "Preferred contact method". Give each radio a clear value so the server knows what was picked.

  4. Styling it is awkward by default

    The legend sits on the fieldset border in a gap the browser cuts for it, and many CSS rules behave oddly there. legend { float: left; width: 100%; padding: 0; } with legend + * { clear: both; } turns it into a normal heading, and fieldset { border: 0; padding: 0; margin: 0; min-width: 0; } resets the box.

  5. A disabled fieldset still shows its legend

    <fieldset disabled> disables every control inside, so none of them are sent, but the legend stays visible and readable. Controls inside the legend itself stay enabled.

Sources: WHATWG HTML Standard: The legend element · MDN: <legend> · W3C WAI: Grouping controls

Copy-paste ready

The HTML Legend Element example below is a complete, working form — paste it into any HTML page and it submits, no edits to the markup required.

No backend to build

Your html legend element form posts to one endpoint. No server, PHP, or API route — accepted submissions are saved to your dashboard before owner notification email is attempted; delivery time and inbox placement depend on provider and recipient settings.

A form that really submits

Unlike a static reference snippet, this <legend> form actually sends data to a free splitforms backend, with spam filtering built in.

How it works

How to add HTML Legend Element to any page.

Copy the html legend element example, drop in your free access key, and paste it into any page — submissions start landing in your dashboard.

Copy the code

Copy the HTML Legend Element example below.

Add your access key

Replace YOUR_ACCESS_KEY with a free splitforms key from the dashboard.

Paste into your site

Drop the form into any HTML page. Submissions arrive in your dashboard.

How SplitForms works

What happens after someone submits your form?

splitforms receives the submission, filters spam, saves it to your dashboard and emails you — then, on paid plans, sends it on to your webhooks and integrations. No backend infrastructure to build.

A SplitForms contact form submission launching straight to your inbox

Add your endpoint

Point your form to your unique SplitForms endpoint. That's it.

HTML form pointing at a SplitForms submit endpoint

Receive submissions

We instantly capture and organize every submission in your inbox.

Submissions inbox with searchable leads and status pills

Route anywhere

Send data to email, spreadsheets, CRMs, webhooks, and 7,000+ apps.

Generic integration tiles for email, sheets, chat, CRM, automate, and webhook

No credit card required. Set up in under 60 seconds.

Connect & automate

Where can submissions go besides email?

On paid plans, submissions can also go to Slack, Discord, Google Sheets, Notion, Airtable, Zapier or any signed webhook — and splitforms works on the platforms you build on, from WordPress and Shopify to Next.js. With Stripe connected, your forms can take payments too.

Connect your SplitForms form to Slack, Google Sheets, Mailchimp, Zapier and more
NewTake payments on your formsDeposits, bookings, order forms — submitters check out through Stripe and the money goes straight to your Stripe account. Included on every paid plan.See payment forms →Need time slots? Online booking →

Setup guides for the stacks you use

Questions

HTML Legend Element questions, answered.

View all FAQs
What is the legend tag used for in HTML?

It gives a caption to a <fieldset>. The legend names the group of controls, such as "Preferred contact method" above three radio buttons, and screen readers read it as the group name.

Does the legend have to be the first element in a fieldset?

Yes. The legend must be the first child of the fieldset. If another element comes first, browsers do not treat it as the caption and screen readers do not announce it as the group name.

How do I label a group of radio buttons accessibly?

Wrap the radios in a <fieldset>, put the question in a <legend> as its first child, give every radio the same name, and give each radio its own <label>. Use role="radiogroup" with aria-labelledby only when a fieldset is not possible.

How do I remove the fieldset border and style the legend like a heading?

Reset the fieldset with border: 0; padding: 0; margin: 0; min-width: 0; then give the legend float: left; width: 100%; padding: 0; and add legend + * { clear: both; } so the next element starts below it.

Is the legend text sent when the form is submitted?

No. Only named form controls are submitted. The legend is a caption, so the server only receives values such as contact_method=email.

Simple pricing

How much does splitforms cost?

Free gives you 500 submissions for $0 — no card, no time limit. Pro is $5/month for 5,000 submissions a month, and Annual is $49/year for 15,000 a month with every Pro feature.

Free

$0— 500 submissions
 

No card, no time limit

Best for testing

For side projects and indie devs.

  • 500 free submissions
  • Unlimited forms
  • Email notifications included
  • Smart spam filtering
  • Submissions dashboard
  • Redirect after submit
  • MCP server included

Annual

$49/ year
About $4.08 per month, billed yearly
Best value

Every Pro feature with triple the volume — $0.27 per 1,000 at full use.

  • 15,000 submissions per month
  • Unlimited forms
  • Everything in Pro
  • File uploads with 5 GB storage
  • 3 team seats
  • Priority email support

No credit card required on Free • Cancel anytime • Full pricing and FAQ