October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Is There an Alternative to
and in HTML?

For grouped form controls, native fieldset and legend remain the best default. Restyle them with CSS; use an ARIA-named group only when native markup is impossible, and omit grouping when individual labels already provide all necessary context.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Usually, no alternative is needed: keep the native <fieldset> and <legend> for a related group of controls, then change their appearance with CSS. Use an ARIA group named by visible text only when a real markup constraint prevents native elements. If each radio or checkbox already has a clear, self-contained label and no shared explanation is needed, you can omit group semantics.

What each element means

<fieldset> is the semantic container for related form controls; <legend> supplies the group caption. The W3C describes the fieldset as a container and the legend as a heading that identifies the group (W3C WAI Forms Tutorial).

As an Amazon Associate I earn from qualifying purchases.

Use the pair when a person needs context that applies to several controls, such as “Preferred contact method” for Email and Phone choices. Keep the legend short, and make every individual label understandable on its own. Assistive technologies differ in whether they announce a legend once, with each control, or infrequently, so a long legend should not carry essential wording by itself (W3C WAI guidance).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep the native markup and restyle it

The border, spacing and legend position are presentation defaults, not semantic requirements. W3C technique H71 specifically discusses overriding the fieldset border and legend positioning, and MDN documents styling for both elements (W3C H71; MDN fieldset; MDN legend).

#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
<fieldset class="choice-group">
  <legend>Preferred contact method</legend>
  <label><input type="radio" name="contact" value="email"> Email</label>
  <label><input type="radio" name="contact" value="phone"> Phone</label>
</fieldset>
.choice-group {
  border: 0;
  margin: 0;
  padding: 0;
}

.choice-group > legend {
  padding: 0;
  font-weight: 600;
}

Adjust the CSS to your design, but do not hide or remove the legend when its group caption is needed. A visually minimal fieldset can still expose the correct structure to browsers and assistive technology.

When native elements cannot be used

If a component system or another technical constraint rules out <fieldset> and <legend>, W3C documents a group container with role="group" and aria-labelledby. Point the attribute to visible text that names the group, and retain an explicit label for every control.

<div role="group" aria-labelledby="contact-heading">
  <h2 id="contact-heading">Preferred contact method</h2>
  <label><input type="radio" name="contact" value="email"> Email</label>
  <label><input type="radio" name="contact" value="phone"> Phone</label>
</div>

This pattern communicates a named group, but it does not recreate every behavior of a native fieldset. Do not add role="group" merely to draw a border or create a layout wrapper; ordinary CSS needs no ARIA.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When no group wrapper is the better choice

For related radio buttons or checkboxes, a fieldset and legend are not required when the instructions are clear, the choices are distinct, and each individual label is sufficiently descriptive. This is the exception described in W3C technique H71 (W3C H71).

For example, a short list of independently named settings may need only correctly associated labels. Add a group caption when users must understand a shared question, instruction, error, or relationship that the individual labels cannot convey.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Native fieldset behavior you may lose

A fieldset is more than a visual box. Under the HTML Standard, disabling a fieldset disables descendant form controls, except controls that are descendants of the fieldset’s first <legend> child (WHATWG HTML Standard, form elements). An ARIA group or generic <div> does not supply that behavior; implement any equivalent disabled-state logic separately.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Choosing the pattern

Situation Recommended markup Reason
Several controls share a question or caption Native <fieldset> with <legend> Provides the intended HTML grouping semantics and native form behavior.
Native elements are impossible because of a genuine implementation constraint Container with role="group" and aria-labelledby Names the group from visible text while preserving individually labelled controls.
Each option is already clear and no shared context is needed Individually labelled controls without a group wrapper Avoids redundant announcements and repeated wording.
Only a visual border or layout region is wanted Ordinary element and CSS ARIA describes meaning, not decoration.

Practical checks before shipping

  • Write a concise legend whenever the controls have shared context.
  • Ensure every input has its own meaningful label; do not rely on the legend to identify an option.
  • Style the native elements instead of replacing them solely because of their default border or spacing.
  • Use the ARIA pattern only when native markup is genuinely unavailable, and reference visible text with aria-labelledby.
  • If you replace a fieldset, review any disabled-state, validation, or scripting behavior that native HTML previously provided.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.