2

In SP on-premise, we could add a content editor web part and add an image in the new form.

I need to do the same thing with SharePoint online, and I am unsure how to do it.

So basically, what I need to do is every time users want to create a new list (form), they should see an image on top of the page.

1
  • Hi @Harris, is my below solution working for you? If yes, please Upvote(^) and accept as an Answer as it helped you & it will help others with similar question in future to find the correct answer easily. It also removes this question from "Unanswered questions" list. Jun 8 at 8:30

1 Answer 1

3

In SharePoint Online modern experience, you can add an image to the list form by applying JSON formatting to the Header section like this:

{
    "elmType": "img",
    "style": {
        "width": "100%",
        "max-width": "100%",
        "float": "left"
    },
    "attributes": {
        "src": "=@currentWeb + '/SiteAssets/Microsoft products banner.jpg'"
    }
}

Output:

enter image description here

Documentation:

Configure the list form

Examples:

The following examples may assist in understanding how the formatting behaves in the header.

Example 01

Without adding display: block to the parent, the parent will have flex applied, children will display inline.

{
    "elmType": "div",
    "children":
    [
        {
            "elmType": "div",
            "txtContent": "Line 01.\n\n"
        },
        {
            "elmType": "div",
            "txtContent": "Line 02.\n\n"
        },
        {
            "elmType": "img",
            "attributes":
            {
                "src": "https://picsum.photos/600/300"
            }
        }
    ]
}

will produce:

enter image description here

Example 02

When adding display: block to the parent, the parent will not have flex applied, children will display as blocks.

{
    "elmType": "div",
    "style":
    {
        "display": "block"
    },
    "children":
    [
        {
            "elmType": "div",
            "txtContent": "Line 01.\n\n"
        },
        {
            "elmType": "div",
            "txtContent": "Line 02.\n\n"
        },
        {
            "elmType": "img",
            "attributes":
            {
                "src": "https://picsum.photos/600/300"
            }
        }
    ]
}

will produce:

enter image description here

Example 03

If you want to modify the sample header that is provided by Microsoft so that is has some text and an image below it, you could try something like this:

{
    "elmType": "div",
    "style":
    {
        "display": "block",
        "width": "99%",
        "border-top-width": "0px",
        "border-bottom-width": "1px",
        "border-left-width": "0px",
        "border-right-width": "0px",
        "border-style": "solid",
        "margin-bottom": "16px",
        "padding-bottom": "20px"
    },
    "children":
    [
        {
            "elmType": "div",
            "attributes":
            {
                "class": "ms-borderColor-neutralTertiary"
            },
            "style":
            {
                "display": "flex"
            },
            "children":
            [
                {
                    "elmType": "div",
                    "style":
                    {
                        "display": "flex",
                        "box-sizing": "border-box",
                        "align-items": "center"
                    },
                    "children":
                    [
                        {
                            "elmType": "div",
                            "attributes":
                            {
                                "iconName": "EditContact",
                                "class": "ms-fontSize-42 ms-fontWeight-regular ms-fontColor-themePrimary",
                                "title": "Details"
                            },
                            "style":
                            {
                                "flex": "none",
                                "padding": "0px",
                                "padding-left": "0px",
                                "height": "36px"
                            }
                        }
                    ]
                },
                {
                    "elmType": "div",
                    "attributes":
                    {
                        "class": "ms-fontColor-neutralSecondary ms-fontWeight-bold ms-fontSize-24"
                    },
                    "style":
                    {
                        "box-sizing": "border-box",
                        "width": "100%",
                        "text-align": "left",
                        "padding": "21px 12px",
                        "overflow": "hidden"
                    },
                    "children":
                    [
                        {
                            "elmType": "div",
                            "txtContent": "My Header Title"
                        }
                    ]
                }
            ]
        },
        {
            "elmType": "div",
            "txtContent": "Line 01.\n\n"
        },
        {
            "elmType": "div",
            "txtContent": "Line 02.\n\n"
        },
        {
            "elmType": "img",
            "attributes":
            {
                "src": "https://picsum.photos/600/300"
            }
        }
    ]
}

will produce:

enter image description here

5
  • 1
    That was useful. I didn't knew about this .Thanks for Sharing
    – Saira
    Sep 23, 2021 at 6:30
  • You're welcome @Saira! Sep 23, 2021 at 6:35
  • Hi @Harris, did you try this? Is it working for you? let me know if you have any further doubt in this. Sep 24, 2021 at 5:10
  • It's a pity the example header layout uses relatively complex nested divs and child divs using flex styling. I'd like to add image and text divs beneath the header icon and text, but can't figure out how to put them on a 'new line'. Am having a 'peter griffin CSS meme' moment. Jan 17 at 3:17
  • I investigated my query further, and made some additions to the answer, to demonstrate how the formatting behaves in regards to flex etc. Jan 17 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.