4.7.x form.inc theme_fieldset($element)
5.x form.inc theme_fieldset($element)
6.x form.inc theme_fieldset($element)
7.x form.inc theme_fieldset($variables)

Returns HTML for a fieldset form element and its children.


$variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #attributes, #children, #collapsed, #collapsible, #description, #id, #title, #value.

Related topics


includes/form.inc, line 2923
Functions for form and batch generation and processing.


function theme_fieldset($variables) {
  $element = $variables['element'];
  element_set_attributes($element, array(
  _form_set_class($element, array(
  $output = '<fieldset' . drupal_attributes($element['#attributes']) . '>';
  if (!empty($element['#title'])) {

    // Always wrap fieldset legends in a SPAN for CSS positioning.
    $output .= '<legend><span class="fieldset-legend">' . $element['#title'] . '</span></legend>';
  $output .= '<div class="fieldset-wrapper">';
  if (!empty($element['#description'])) {
    $output .= '<div class="fieldset-description">' . $element['#description'] . '</div>';
  $output .= $element['#children'];
  if (isset($element['#value'])) {
    $output .= $element['#value'];
  $output .= '</div>';
  $output .= "</fieldset>\n";
  return $output;


diqidoq’s picture

I thought this may be of interest to users dealing with collapsible fieldset issues -> http://drupal.org/node/1099132

paulsheldrake’s picture

One thing to remember for this if you're calling it directly from a theme function there needs to be an inner 'element' array that then keeps the '#title', '#value' keys in it.

$fieldset_vars = array(
  'element' => array(
    '#title' => t('My Heading'),
    '#value' => t('hello world'),
    '#children' => '<div>',

$output = theme('fieldset', $fieldset_vars);