Skip to main content

Customize the look of the sign-in page

This guide explains how to change the look of the sign-in page of an application: the background image, the style of the sign-in form, its position, and an optional side panel.


Learning outcomes​

  • Set a background image.
  • Style the sign-in form with CSS.
  • Position the form and add a side panel.
  • Move the design to the same application on another Casdoor instance.
  • Know what an organization admin can put in custom HTML and CSS.

What you need​


All settings on this page are on the UI Customization tab of the application edit page. The preview on the tab updates as you change them. This is the result of the steps below:

Sign-in page with background, side panel, and styled form

Set a background image​

The default background is white.

Sign-in page with the default background

  1. Set Background URL to the URL of an image. The preview updates when the URL is valid.

    Recording of setting the Background URL

  2. To use another image on phones, set Background URL Mobile.

  3. To use another image when the sign-in page is shown in dark mode, set Background URL Dark.

  4. To show a different image now and then, add more images to More background URLs. Each visit to the sign-in page shows one of them or Background URL, picked at random.

On a phone, Background URL Mobile takes precedence over the others. When you apply a theme from the Marketplace, Casdoor saves these settings and restores them when you remove the theme.

Style the sign-in form​

  1. Enter CSS rules in Custom CSS, for example:

    .login-panel{
    padding: 40px 30px 0 30px;
    border-radius: 10px;
    background-color: #ffffff;
    box-shadow: 0 0 30px 20px rgba(0, 0, 0, 0.20);
    }

    Recording of editing Custom CSS

  2. To use other rules on phones, set Custom CSS Mobile.

caution

Enter plain CSS rules only. Casdoor puts the content of Custom CSS and Custom CSS Mobile into a <style> element itself, so a <style> wrapper of your own breaks the rules.

If Custom CSS is empty, the editor can show a default. To start from it, copy it into the field and save.

Sign-in page with the styled form

The main containers of the form are .login-panel and .login-form. Target them for further changes.

Position the form​

In Form position, select Left, Center, or Right.

Form position setting

Sign-in page with the form on the left

Add a side panel​

  1. In Form position, select Enable side panel. The form moves to the center, with a panel beside it.

    Enable side panel option

  2. Enter the content of the panel in Side panel HTML. Start from the default template or write your own. Unlike Custom CSS, this field takes HTML, so a <style> element inside it is fine:

    <style>
    .left-model{
    text-align: center;
    padding: 30px;
    background-color: #8ca0ed;
    position: absolute;
    transform: none;
    width: 100%;
    height: 100%;
    }
    .side-logo{
    display: flex;
    align-items: center;
    }
    .side-logo span {
    font-family: Montserrat, sans-serif;
    font-weight: 900;
    font-size: 2.4rem;
    line-height: 1.3;
    margin-left: 16px;
    color: #404040;
    }
    .img{
    max-width: none;
    margin: 41px 0 13px;
    }
    </style>
    <div class="left-model">
    <span class="side-logo"> <img src="https://cdn.casbin.org/img/casdoor-logo_1185x256.png" alt="Casdoor" style="width: 120px">
    <span>SSO</span>
    </span>
    <div class="img">
    <img src="https://cdn.casbin.org/img/casbin.svg" alt="Casdoor"/>
    </div>
    </div>
  3. Adjust the form in Custom CSS. Again, enter rules without a <style> wrapper:

    .login-panel{
    border-radius: 10px;
    background-color: #ffffff;
    box-shadow: 0 0 30px 20px rgba(0, 0, 0, 0.20);
    }
    .login-form {
    padding: 30px;
    }

    Recording of adjusting Custom CSS for the side panel

Move the design to another instance​

To move the design of an application to the same application on another Casdoor instance, for example from staging to production, use Export JSON and Import JSON at the bottom of the application edit page. The buttons appear when you edit an existing application.

  1. On the source instance, click Export JSON. Casdoor copies a JSON document to the clipboard.
  2. On the target instance, open the same application and click Import JSON.
  3. Paste the JSON and click OK. Casdoor fills in the fields.
  4. Click Save.

The JSON contains the name and the organization of the application and the following fields: Logo, Favicon, Background URL and its mobile variant, Custom CSS and its mobile variant, the position and offset of the form, Side panel HTML, the theme, and the header, footer, sign-up, and sign-in HTML. It contains no secrets, providers, or other settings.

note

The name and the organization in the JSON must match the target application. Otherwise, Casdoor rejects the import. The import moves a design between instances, not between different applications.

What organization admins can put in custom HTML and CSS​

Global administrators can save any HTML and CSS. When an organization admin adds or updates an application, in the admin console or through the Casdoor MCP server, Casdoor checks each of these fields that the admin changed:

  • Header HTML, Page HTML, Footer HTML, Side panel HTML, Signin HTML, and Signup HTML
  • Custom CSS and Custom CSS Mobile
  • The Custom CSS of the sign-in items, which custom sign-in items render as HTML
  • The Custom CSS of the sign-up items, and the Label of the Text sign-up items, which Casdoor renders as HTML

Fields that the admin didn't change keep their value, even if it breaks the rules below. If a changed field breaks them, Casdoor rejects the save with an error that names the fields: "the <fields> of the application uses HTML or loads files that this Casdoor only lets a global admin set: ...".

HTML rules​

  • Only layout and text elements are allowed: for example div, span, p, headings, lists, a, img, tables, section, details and summary, center, font, style, and basic svg shapes and gradients. script, form, input, iframe, and other elements are refused, unless a global admin adds them to Allowed custom HTML elements in the global settings. script can't be added; scripts need Enable custom scripts, which only a global admin can turn on.
  • Event handler attributes (on...) are refused, as are attributes such as srcset, action, formaction, srcdoc, contenteditable, and xlink:href.
  • href is allowed only on a, with a relative URL or an http, https, mailto, or tel URL.
  • src is allowed only on img and on the elements in Allowed custom HTML elements. Its URL, the data attribute of object, the background and poster attributes, and any url() in an attribute follow the URL rule below.
  • HTML comments and doctypes are refused.

CSS rules​

  • The CSS must not contain \, <, image(, image-set(, cross-fade(, element(, or src(.
  • Every url() is relative, a data: URL, a # reference, or starts with an allowed prefix.
  • @import is allowed only from https://fonts.googleapis.com/css, https://cdn.jsdelivr.net/npm/@fontsource/, and https://cdn.jsdelivr.net/npm/@fontsource-variable/.

The allowed prefixes are:

  • https://fonts.googleapis.com/ and https://fonts.gstatic.com/
  • https://cdn.jsdelivr.net/gh/casdoor/, https://cdn.jsdelivr.net/npm/@fontsource/, and https://cdn.jsdelivr.net/npm/@fontsource-variable/
  • https://cdn.casbin.org/, https://cdn.casdoor.com/, and https://cdn.casvisor.com/
  • The origin of this Casdoor
  • The Domain of each Storage provider of the admin owner
  • Each entry of Allowed custom HTML URLs in the global settings
  • Each entry of formCssAllowedUrls in conf/app.conf, a comma-separated list that is empty by default. See Configuration.

A global admin sets both lists on the Global Settings page (/settings), and the change applies to all organizations without a restart.

For example, to let organization admins use background images from your own image host, add https://img.example.com/ to Allowed custom HTML URLs. To let them embed YouTube videos, also add iframe to Allowed custom HTML elements and https://www.youtube.com/embed/ to Allowed custom HTML URLs.

The error of a rejected save names the field and what in it isn't allowed, for example page HTML (<iframe>) or page HTML (the src attribute of <iframe>).

On the sign-in pages, Casdoor also removes scripts from the custom HTML of applications outside the built-in organization. See Custom HTML and scripts.

See also​