Languages
[Edit]
EN

HTML - simple group box example

3 points
Created by:
Kevin
797

In this article, we would like to show you how to create a simple group box using the fieldset element in HTML.

Quick solution:

// ONLINE-RUNNER:browser;

<fieldset>
  <legend>Box title</legend>
  <!-- Put HTML element here ... -->
</fieldset>

 

Practical example

In this example, we create a simple group box using the fieldset element. Inside the group box, we use legend element to specify the box title and we put in some inputs (wrapped with label elements, so we don't need to use id-for attributes relation).

Runnable example:

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <form>
    <fieldset>
      <legend>Color chooser</legend>
      <label>
        <input type="radio" name="color" />
        <span>Red</span>
      </label>
      <br />
      <label>
        <input type="radio" name="color" />
        <span>Green</span>
      </label>
      <br />
      <label>
        <input type="radio" name="color" />
        <span>Blue</span>
      </label>
    </fieldset>
  </form>
</body>
</html>

 

References

  1. <fieldset>: The Field Set element - HTML: HyperText Markup Language | MDN

Alternative titles

  1. HTML - group inputs and labels in box using fieldset
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join