diff --git a/includes/common.inc b/includes/common.inc
index 4b722580e2..6b0ef44f2f 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -5769,6 +5769,36 @@ function drupal_pre_render_conditional_comments($elements) {
   return $elements;
 }
 
+/**
+ * TODO
+ */
+function drupal_pre_render_htmltag_markup(array $elements) {
+  $void_elements = array(
+    'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
+    'link', 'meta', 'param', 'source', 'track', 'wbr',
+  );
+
+  $attributes = isset($elements['#attributes']) ? drupal_attributes($elements['#attributes']) : '';
+
+  $open_tag = '<' . $elements['#tag'] . $attributes;
+  $close_tag = '</' . $elements['#tag'] . '>';
+
+  // Construct a void element.
+  if (in_array($elements['#tag'], $void_elements, TRUE)) {
+    $open_tag .= ' />';
+    $close_tag = '';
+    $elements['#markup'] = NULL;
+  } else {
+    $open_tag .= '>';
+    $elements['#markup'] = $elements['#value'];
+  }
+
+  $elements['#prefix'] .= $open_tag;
+  $elements['#suffix'] = $close_tag . $elements['#suffix'] ."\n";
+
+  return $elements;
+}
+
 /**
  * #pre_render callback to render a link into #markup.
  *
diff --git a/includes/theme.inc b/includes/theme.inc
index 5b602f8d7f..97f1b8df6b 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -2316,22 +2316,8 @@ function theme_feed_icon($variables) {
  */
 function theme_html_tag($variables) {
   $element = $variables['element'];
-  $attributes = isset($element['#attributes']) ? drupal_attributes($element['#attributes']) : '';
-  if (!isset($element['#value'])) {
-    return '<' . $element['#tag'] . $attributes . " />\n";
-  }
-  else {
-    $output = '<' . $element['#tag'] . $attributes . '>';
-    if (isset($element['#value_prefix'])) {
-      $output .= $element['#value_prefix'];
-    }
-    $output .= $element['#value'];
-    if (isset($element['#value_suffix'])) {
-      $output .= $element['#value_suffix'];
-    }
-    $output .= '</' . $element['#tag'] . ">\n";
-    return $output;
-  }
+
+  return $element['#markup'];
 }
 
 /**
diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test
index 710a56e5ef..3136b53452 100644
--- a/modules/simpletest/tests/theme.test
+++ b/modules/simpletest/tests/theme.test
@@ -546,6 +546,45 @@ class RenderElementTypesTestCase extends DrupalWebTestCase {
         ),
         'expected' => '<title>title test</title>' . "\n",
       ),
+      // Test html tag with nested elements.
+      array(
+        'name' => "#type 'html_tag' with nested elements",
+        'value' => array(
+          '#type' => 'html_tag',
+          '#tag' => 'div',
+          'child1' => array(
+            '#type' => 'html_tag',
+            '#tag' => 'em',
+            '#value' => 'test',
+          ),
+          'child2' => array(
+            '#type' => 'html_tag',
+            '#tag' => 'span',
+            '#value' => 'value',
+          ),
+        ),
+        'expected' => '<div><em>test</em>' . "\n" . '<span>value</span>' . "\n" . '</div>' . "\n",
+      ),
+      // Test html tag with nested elements.
+      array(
+        'name' => "#type 'html_tag' with nested elements",
+        'value' => array(
+          '#type' => 'html_tag',
+          '#tag' => 'div',
+          '#value' => 'title test',
+          'child1' => array(
+            '#type' => 'html_tag',
+            '#tag' => 'em',
+            '#value' => 'test',
+          ),
+          'child2' => array(
+            '#type' => 'html_tag',
+            '#tag' => 'span',
+            '#value' => 'value',
+          ),
+        ),
+        'expected' => '<div>title test</div>' . "\n",
+      ),
     );
 
     $this->assertElements($elements);
diff --git a/modules/system/system.module b/modules/system/system.module
index 2534421864..762d56a870 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -313,9 +313,14 @@ function system_element_info() {
   );
   $types['html_tag'] = array(
     '#theme' => 'html_tag',
-    '#pre_render' => array('drupal_pre_render_conditional_comments'),
+    '#pre_render' => array(
+      'drupal_pre_render_conditional_comments',
+      'drupal_pre_render_htmltag_markup',
+    ),
     '#attributes' => array(),
     '#value' => NULL,
+    '#prefix' => NULL,
+    '#suffix' => NULL,
   );
   $types['styles'] = array(
     '#items' => array(),
