A Short Overview of the Guide

This guide provides detailed step-by-step instructions on how to apply custom CSS to CRM forms, which means using a combination of JavaScript and web resources, including several examples of its use.

A Short Reference About the Author

Mykhailo is a qualified Dynamics 365 Developer with deep practical experience working with Dynamics 365 and the Power Platform, including developing and customizing Dynamics 365 CRM and connected external portals.

Introduction

Customizing the appearance of Microsoft Dynamics CRM forms can significantly reinforce user experience and align the CRM interface with your company's branding. Applying custom CSS to CRM forms involves a combination of JavaScript and web resources.

Practical Considerations When Applying Custom CSS in Dynamics 365

When applying custom CSS to Dynamics 365 CRM forms, it is important to understand which elements can be modified effectively and how to apply changes without affecting the overall user experience. Custom CSS is commonly used for visual improvements such as changing field appearance, highlighting important information, adjusting spacing, hiding unnecessary visual elements, and improving the readability of forms.

Some of the most common practical scenarios may include the following:

  • Highlighting important fields

CSS can be applied to fields such as status, priority, approval indicators, or customer information to make critical data more visible. For example, a field can be given a different background color when a record requires attention.

  • Customizing sections and tabs

Developers can adjust the appearance of form sections by changing colors, borders, font sizes, and spacing. This can help separate logical areas of a form and make complex forms easier for users to navigate.

  • Modifying the subgrid appearance

CSS can be used to customize subgrid elements, such as hiding unnecessary action icons, adjusting row styling, or emphasizing specific records. Since subgrids load asynchronously, CSS selectors are often more reliable than JavaScript-based modifications for purely visual changes.

  • Improving the user guidance

Visual indicators can be added to help users understand the purpose of fields or sections. For example, required information, warnings, or important business conditions can be emphasized through styling.

  • Applying the company’s branding

Custom colors, fonts, and visual elements can help align CRM forms with company branding standards.

When creating CSS selectors, it is recommended to target elements as specifically as possible. Using unique field IDs, subgrid IDs, or custom classes reduces the risk of unintentionally affecting other parts of the form. Avoid relying heavily on automatically generated Microsoft internal class names because these may change after Dynamics 365 updates.

Before deploying CSS customizations to a production environment, test them with different browsers, security roles, form configurations, and major Dynamics 365 releases to ensure consistent behavior.

Applying Custom CSS to Dynamics CRM Forms

To apply custom CSS to D365 CRM forms, it is necessary to go through the procedures offered below.

To create a Web Resource for JavaScript, take these actions:

  1. Go to the “Settings > Customizations > Customize the System”.

  2. Click on the “Web Resources”.

  3. Click on the “New” to create a new web resource.

  4. Set the Name.

  5. Display the "Name" and the "Description" fields.

  6. Opt JavaScript (JScript) as the type.

  7. Add one of the given below JavaScript codes to embed the CSS:

    If you want to use the static CSS from the external CSS file:

    
        
        let loadCustomCSS = function () {
      let link = document.createElement('link');
      link.rel = 'stylesheet';
      link.type = 'text/css';
      link.href = 'here path of CSS file';
      link.media = 'all';
      document.getElementsByTagName('head')[0].appendChild(link);
    };
    
    
    

    If you want to use the inline CSS:

    
        
        let loadCustomCSS = function () {
      let style = document.createElement('style');
      style.type = 'text/css';
      style.innerHTML = `
        /* Here, your custom CSS */
      `;
      document.getElementsByTagName('head')[0].appendChild(style);
    };
    
    
    
  8. Save the web resource and publish it.

To add the JavaScript Web Resource to the form where you want to apply the custom CSS, perform the following:

  1. Proceed to the “Settings > Customizations > Customize the System”.

  2. Choose the entity you want to customize.

  3. Open the form editor for the desired form.

  4. Append the "Form Libraries”. For this, in the form editor, click on the "Form Properties”. Under the "Form Libraries”, click on the “Add” and select the JavaScript web resource you have produced.

  5. Add the “Onload Event”. For this, under the “Event Handlers”, select the “Form Onload”. Click on the “Add” and pick the function “loadCustomCSS” from the JavaScript web resource. Make certain the “Enabled” is checked.

  6. Save the form and publish the customizations.

Examples of Using CSS in Subgrids

One common drawback of customizing subgrids with JavaScript is the necessity to add a timeout until the subgrid is loaded. This action is compulsory because subgrids are loaded asynchronously after the main form. However, no such delay is necessary for CSS changes, which is a significant benefit. We can apply CSS before the subgrids load, and it will work just fine.

To easily hide the “Delete” button for each record in a subgrid, you can use this code:

    
    let loadCustomCSS = function () {
  let style = document.createElement('style');
  style.type = 'text/css';
  style.innerHTML = `#SubgridId .ms-crm-ImageStrip-deleteButtonBin
    {
      display: none !important;
    }`;
  document.getElementsByTagName('head')[0].appendChild(style);
};



how to apply Custom CSS to Dynamics CRM Forms

! Note. You can be more flexible by incorporating conditions based on different criteria.

To hide the delete button for a specific record by using its recordId (GUID), use such a code:

    
    let loadCustomCSS = function () {
  let style = document.createElement('style');
  style.type = 'text/css';
  style.innerHTML = `tr[oid="{77fb6b61-8818-4c60-b8c9-dfb63f17fffa}"] img
    {
      display: none !important;
    }`;
  document.getElementsByTagName('head')[0].appendChild(style);
};



In this case, we target the row (tr) with the attribute “oid” that matches the specific recordId (GUID).

Prettify Form Elements

To receive a prettify form element, you may utilize this code:


    
    let loadCustomCSS = function () {
  let style = document.createElement('style');
  style.type = 'text/css';
  style.innerHTML = `#address1_line2_cl
    {
      background-color: green !important;
      color: black !important;
      font-size: 20px !important;
      font-weight: bold !important;
    }`;
  document.getElementsByTagName('head')[0].appendChild(style);
};


CSS Tricks for Dynamics CRM Form Elements - Prettify Form Elements

Conclusion

Custom CSS can be loaded into Dynamics CRM forms, allowing you to style the interface, customize the elements easily, and integrate with your logic. You have seen a simple and effective way to hide elements in subgrids using custom CSS, which is particularly useful given their asynchronous loading.

Frequently Asked Questions