How to insert a custom Script inside a Modern WebSite page ?

New Contributor

Hi all,

in a modern website page (communication website) inside sharepoint i need to insert something like this. Is this feasilble or not ? Expecially the script inside the < head > tag ?

Thanks a lot  !

Best regards


Add the following script between the< head > and < /head > tags 

<script src="https://XXXXXXYYYY.come/integration/test_js.php?&h=400& &typeView=small&CodP=&separateP=" type="text/javascript"></script>


Add the following codes between the tag < body > and < /body > 

<div id="inxxxx_yyyyy"></div>

<script type="text/javascript">


        fontFamily: "Open Sans",

        bgColor: "FFFFFF",

        bgRowVacancy: "FDFDFD",

        separatoColor: "AAAAAA",

        filterColor: "494444",

        filterActiveColor: "42B2E5",

        jobTitleColor: "494444",

        jobTitleActiveColor: "42B2E5",

        jobDescColor: "888888",

        jobInfoColor: "494444",




3 Replies

@Roberto Ialino out-of-the-box this isn't possible as Microsoft have locked it down so that sites don't break when Microsoft make any changes. You might be able to achive this with SPFX but someone like @ganeshsanap would have to answer that as I'm not permitted to use SPFx at my company.


Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

Thanks for the mention @RobElliott 


@Roberto Ialino You can inject custom JavaScript/CSS on modern pages using SPFx. Check my answer for more information at:  Running modern 2022 native Web Components in Microsoft365/SharePoint Online 


Note: DOM manipulation & CSS customizations are not recommended by Microsoft and some of your customization may break if Microsoft changes HTML element id/classes in new release updates.

Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Thanks a lot both !!!