Search code examples
cssdjangoformslabeldjango-users

Change label color of Django user form


I added a user module to my project and I used the default Django user model for that. I've to change the styling to suit my other pages. The background color is black. The problem is default labels and error messages (eg: "username", "password", "Enter the same password as before for verification") generated by Django is also black and not visible now. How to change the label colors so that they are visible again? I'm a newbie to both development & StackOverflow, apologies if I have used incorrect terms or tags in my question. Thanks in advance.screenshot of the login form (highlighted is my problem

This is my forms.py (users app)

from django.contrib.auth.forms import UserCreationForm

class CustomUserCreationForm(UserCreationForm):
    class Meta(UserCreationForm.Meta):
        fields = UserCreationForm.Meta.fields + ("email",)

this is from my login.html

<h2>Login</h2> 

<div>
<form method="post" class="loginfrm">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Login" class="loginbtn">
</form>
</div>

Solution

  • I've figured it out, thanks to Mubashar Javed's comment.

    <form method="post" class="loginfrm">
    

    I had to apply the style to this class, any style I apply to this class, only affects the labels. Exactly what I wanted.

    <style>
    .loginfrm {
        color: white;
    }
    </style>
    

    you can see that my problem is now fixed.