Div

class crispy_forms_gds.layout.Div(*fields, **kwargs)

A layout object for displaying a general-purpose Div. This is not a Design System component but is included as it’s a basic part of django-crispy-forms.

Although there is the Fieldset component for grouping fields together a Div is quite useful when you just need to add some spacing between elements.

Examples:

Div("name", "email", "phone", css_class="govuk-!-margin-bottom-5")
Div("street", "city", "post_code")
Parameters
  • css_id (str, optional) – an unique identifier for the <div>. Generally you will need to set this if you need to add some javascript or very specific styling.

  • css_class (str, optional) – the names of one or more CSS classes that will be added to the <div>. This parameter is for any styling you want to apply. Nothing is added by default.

  • template (str, optional) – the path to a template that overrides the one normally used.

  • *fields – a list of layout objects - fields, buttons, HTML, etc. that displayed inside the <div> element.

  • **kwargs – any additional attributes you want to add to the parent <div>.