Custom CSS in Dynamics 365 Forms? Yeah You Can Do That…But You Shouldn’t.

Have your ever wanted, or were asked, to customize your Dynamics web forms with custom CSS? Well, you can’t. At least not in any supported manner. However, here’s something you can do, that you shouldn’t, because like I said, it’s not supported.

  1. Add a Stylesheet WebResource with your custom css to your solution and name it /styles/customstyles.css
  2. Add your custom CSS to the customstyles.css
  3. Create a Javascript WebResource and add the following function to it
function LoadCustomCss() {

    myWindow = window.parent;
    if (myWindow != null) {
        if (!myWindow.document.getElementById('customSCCss')) {
            var head = myWindow.document.getElementsByTagName('head')[0];
            var stylesheet = myWindow.document.createElement('link');
            stylesheet.id = 'customSCCss';
            stylesheet.type = 'text/css';
            stylesheet.href = Xrm.Page.context.prependOrgName('/WebResources/new_/styles/customstyles.css');
            stylesheet.rel = 'stylesheet';
            head.appendChild(stylesheet);
        }
    }
}
  1. In the OnLoad of your Form call LoadCustomCss and enjoy how easily you were able to add custom css to your Dynamics form, but seriously don’t do this. It’s not supported.

If you do, do this, expect any and / or all Dynamics updates to break it. Also, this is for the classic Web UI and I’ve tested it in the browser interface for version 8.2 on-prem only. So, it probably won’t work in either 9.x or the Unified Interface.

Did I mention this isn’t supported? Here’s a sample of some pretty cool custom subgrid styling you can do, but shouldn’t.

 

Leave a Reply

I’m Mike!

I’m a Microsoft MVP with over 20 years of experience in building business applications using Dynamics and Power Platform, I am deeply passionate about technology. My goal is to share my knowledge and insights to help others navigate the ever-evolving tech landscape. I hope you find something here that brightens your day or makes your work a bit easier.

Let’s connect

Discover more from Power Platform Perspectives from Mike Factorial

Subscribe now to keep reading and get access to the full archive.

Continue reading