Skip to content

ReferenceFor module developers, theme developersDrupal 11

Render array properties

A render array is a structured description of output. Keys starting with # are properties Drupal interprets; everything else is a child element. The render pipeline explains how arrays become HTML; this page lists the properties and element types you write by hand.

$build = [
'#type' => 'container',
'#attributes' => ['class' => ['event-summary']],
'title' => [
'#type' => 'html_tag',
'#tag' => 'h2',
'#value' => $this->t('Upcoming events'),
],
'#cache' => [
'tags' => ['node_list:event'],
'contexts' => ['user.permissions'],
],
];
PropertyTypeDescription
#typestringA render or form element type; pulls in that element’s defaults.
#themestringA theme hook that renders this array. Add __suggestion for a template suggestion.
#markupstringA short HTML string, filtered for XSS. For trusted, larger output use #theme or a template.
#plain_textstringText that is HTML-escaped. Takes precedence over #markup.
#prefix / #suffixstringMarkup placed before / after the element’s output.
#weightfloatSort order among siblings; lower renders first.
#attributesarrayHTML attributes, e.g. ['class' => ['foo'], 'id' => 'bar'].
#attachedarrayAsset libraries, drupalSettings, HTTP headers, and html_head to attach.
#cachearrayCacheability: keys, contexts, tags, max-age. See caching.
#accessbool | AccessResultWhen FALSE, or when an AccessResult is not allowed (neutral or forbidden), the element and its children are not rendered. The result’s cacheability still bubbles.
#pre_render / #post_renderarrayCallables that transform the element before / after rendering.
#lazy_builderarray[callback, [args]] to build highly dynamic parts late, behind a placeholder.
PropertyTypeDescription
#titlestringThe element’s label.
#descriptionstringHelp text shown with the element.
#default_valuemixedThe value before the user edits it.
#requiredboolMarks the field required and adds validation.
#optionsarrayvalue => label choices for select, radios, checkboxes.
#ajaxarrayWire an element to an Ajax callback (callback, wrapper, event).
#valuemixedA fixed value the user cannot edit (used by the value type).

Set with #type. Each is a class under core's Render/Element directory.

#typeRenders
containerA wrapper div for grouping children.
html_tagA single tag (#tag, #value, #attributes).
linkA link (#title, #url).
tableAn HTML table (#header, #rows).
detailsA collapsible <details> section.
fieldsetA grouped set of fields with a legend.
inline_templateA short Twig string rendered in place (#template, #context).
processed_textText run through a text format (#text, #format).
componentA single-directory component (#component, #props, #slots).
#typeInput
textfield / textareaSingle- and multi-line text.
email / tel / url / numberHTML5 typed inputs with built-in validation.
selectA dropdown (#options).
radios / checkboxesGrouped choices (#options).
checkboxA single boolean.
date / datetimeDate and date-time pickers.
managed_fileAn upload handled by the File module.
entity_autocompleteAutocomplete for entity references (#target_type).
machine_nameA machine name derived from another field.
actionsThe button group at the bottom of a form.
submit / buttonButtons.
value / hiddenCarry data without (and with) a hidden input.

Was this page helpful?

Drupal is a registered trademark of Dries Buytaert.