Django Form Styling with Bootstrap

Ruth Jul 09, 2026

Styling Django forms with Bootstrap is a common task for web developers looking to create responsive and visually appealing forms. Django, a high-level Python Web framework, provides a lot of flexibility in form rendering, and Bootstrap, a popular CSS framework, offers a wide range of pre-built components and styles. By combining these two, you can create stunning forms that are both functional and attractive.

Style Django Allauth with Bootstrap & Crispy Forms
Style Django Allauth with Bootstrap & Crispy Forms

In this article, we'll explore how to style Django forms using Bootstrap. We'll cover the basics of Django form rendering, how to include Bootstrap in your Django project, and step-by-step guides to styling various form elements. By the end of this guide, you'll have a solid understanding of how to create beautiful forms using Django and Bootstrap.

Chapter 12: Implementing Schema Markup
Chapter 12: Implementing Schema Markup

Setting Up Bootstrap with Django

Before we start styling our forms, we need to include Bootstrap in our Django project. You can use the official Bootstrap CDN or download and host the Bootstrap files yourself. For simplicity, let's use the CDN.

Django Bootstrap Base Template
Django Bootstrap Base Template

In your base template (usually base.html), add the following lines in the section to include Bootstrap CSS and JS:

```html ```

Styling Django Forms with Bootstrap Classes

Django Templates for CRUD Views
Django Templates for CRUD Views

Django forms are rendered as HTML by default, and we can use Bootstrap classes to style them. Let's start with a simple example. In your Django form, you might have a CharField like this:

```python from django import forms class ContactForm(forms.Form): name = forms.CharField(max_length=100) ```

To style this field with Bootstrap, you can use the form-control class in your template:

```html

{% csrf_token %}
```

The form-control class adds basic styling to the input field, and the mb-3 class adds margin-bottom for spacing. The label and input fields are wrapped in a div with the Bootstrap utility class mb-3 to control vertical spacing.

Django Models – choices Option
Django Models – choices Option

Styling Form Validation Errors

Django provides form validation errors out of the box, but the default styling is not very attractive. We can use Bootstrap to style these errors. First, let's add some error styling to our base template:

```html {% if form.non_field_errors %}

{{ form.non_field_errors }}
{% endif %} {% for field in form %} {% if field.errors %}
{{ field.errors }}
{% endif %} {% endfor %} ```

The alert-danger class adds a red background to the error messages, making them stand out. The non_field_errors template variable is used to display non-field-specific errors, while the field.errors variable is used to display errors for specific fields.

Django Middleware
Django Middleware

Using Bootstrap Components in Django Forms

Bootstrap offers a wide range of components that we can use to enhance our forms. Let's look at a few examples.

Django Views
Django Views
Creating and Maintaining Django Webapps for CollectionSpace
Creating and Maintaining Django Webapps for CollectionSpace
How Django Handles HTTP Requests & Responses
How Django Handles HTTP Requests & Responses
🔗 Django Models – Relationship Fields
🔗 Django Models – Relationship Fields
Django Models – Field Options Explained
Django Models – Field Options Explained
Django Rest Framework
Django Rest Framework
Django Model Relationships
Django Model Relationships
the web page for django
the web page for django
Add Links with the {% url %} Tag in Django Templates
Add Links with the {% url %} Tag in Django Templates
Add Google Login to Your Django App with Allauth
Add Google Login to Your Django App with Allauth
⚙️ Django Generic Views – Build Faster with Less Code
⚙️ Django Generic Views – Build Faster with Less Code
Understanding Django's MVT Framework
Understanding Django's MVT Framework
Django Allauth: Email Verification (Console Method)
Django Allauth: Email Verification (Console Method)
✅ Add Models in Django Admin (admin.py)
✅ Add Models in Django Admin (admin.py)
Customer Feedback System Project in Django with Source Code
Customer Feedback System Project in Django with Source Code
Unveiled Secret! Elite Python, Java, JS Expertise: Stop Searching, Start Shining – Assured Mastery!
Unveiled Secret! Elite Python, Java, JS Expertise: Stop Searching, Start Shining – Assured Mastery!
an image of a computer screen with the text'domine o orm - ele e seu mehror amigo no diano django
an image of a computer screen with the text'domine o orm - ele e seu mehror amigo no diano django
Reasons to learn Django | Geekboots
Reasons to learn Django | Geekboots
Django SchemaEditor
Django SchemaEditor
W3CMS - Pre-Build Django CMS Admin + Frontend
W3CMS - Pre-Build Django CMS Admin + Frontend

Using Bootstrap Input Groups

Input groups allow you to combine form controls like text inputs, button groups, and dropdown menus. They're great for creating complex form elements. Here's an example of an input group with a text input and a button:

```html

@example.com
```

The input-group class is used to create the input group, and the input-group-text class is used to style the button. The mb-3 class adds margin-bottom for spacing.

Using Bootstrap Form Select

Bootstrap's form-select class can be used to style Django's ChoiceField. Here's an example:

```python from django import forms class ContactForm(forms.Form): subject = forms.ChoiceField(choices=[('news', 'News'), ('help', 'Help')]) ```

In your template, you can use the form-select class to style the select element:

```html

```

The form-select class adds basic styling to the select element, and the mb-3 class adds margin-bottom for spacing.

Styling Django forms with Bootstrap is a powerful way to create responsive and visually appealing forms. By using Bootstrap classes and components, you can quickly and easily style your forms without having to write a lot of custom CSS. Whether you're creating simple contact forms or complex user registration forms, Django and Bootstrap make a great pair.