# Customize forms.CheckboxInput HTML rendering

**URL:** <https://forum.djangoproject.com/t/customize-forms-checkboxinput-html-rendering/7066>\
**Category:** Using Django\
**Created:** [March 15, 2021, 7:13pm UTC](https://forum.djangoproject.com/t/customize-forms-checkboxinput-html-rendering/7066 "2021-03-15T19:13:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitagora04](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pitagora04/32/1019_2.png) [@pitagora04](https://forum.djangoproject.com/u/pitagora04)\
**Post date:** [March 15, 2021, 7:13pm UTC](https://forum.djangoproject.com/t/customize-forms-checkboxinput-html-rendering/7066/1 "2021-03-15T19:13:15Z")

</div>

I’m using `forms.ModelForm` to define form.  
As one of the widgets I have `forms.CheckboxInput`.

The problem I have is that `forms.CheckboxInput` is rendering `<label>` before `<input>`.

**How can I achieve that `<input>` is rendered before `<label>` ?**

I have many other fields in the model, so going to rewrite the whole thing manually is really not an option for me because I like what I get with `forms.ModelForm` - I have only a problem with `forms.CheckboxInput`.  
So please suggest how to solve this quickly…

```auto
# forms.py
class SubscriberCreateForm(forms.ModelForm):
    class Meta:
        model = Subscriber
        fields = # many fields
        widgets = {
			# many other fields
			'has_consented':forms.CheckboxInput(attrs={'id': 'checkbox'}),
        }
        labels = {
            # many other fields
			'email':'I confirm...',
        }

```

This is rendered HTML:

```auto
<!-- Rendered HTML -->
<p>
    <label for="checkbox">I confirm...</label>
    <input type="checkbox" name="has_consented" id="checkbox">
</p>

```

And this is what I need:

```auto
<p>
    <input type="checkbox" name="has_consented" id="checkbox">
    <label for="checkbox">I confirm...</label>
</p>

```

Thank you !!

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 15, 2021, 7:46pm UTC](https://forum.djangoproject.com/t/customize-forms-checkboxinput-html-rendering/7066/2 "2021-03-15T19:46:31Z")

</div>

I would suggest creating a custom template (based on the existing checkbox template), and create a custom widget that would use your template. You can then define that checkbox to use your custom widget.

---

<div class="post-metadata">

**Author:** ![pitagora04](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pitagora04/32/1019_2.png) [@pitagora04](https://forum.djangoproject.com/u/pitagora04)\
**Post date:** [March 16, 2021, 7:11pm UTC](https://forum.djangoproject.com/t/customize-forms-checkboxinput-html-rendering/7066/3 "2021-03-16T19:11:48Z")

</div>

Thanks.

I inherited original CheckboxInput class and just point to my customly created checkbox template:

```auto
class CustomCheckboxInput(forms.CheckboxInput):
    template_name = 'myapp/forms_widgets/checkbox_custom.html'

```
