1

I have a list with a hyperlink field. I want to format the link to look like a button. I have tried a gazillion websites, gotten all kinds of CSS, but none of it seems to work.

I've tried two approaches - creating a button and creating an anchor hyperlink. The button type doesn't seem reasonable, as the "action" value set is limited to row list actions (open, edit, delete, etc.)

Here's a sample of what I've tried using an anchor hyperlink:

{
  "elmType": "a",
  "txtContent": "Go to Client Data",
  "style": {
    "text-align": "center",
    "display": "inline-block",
    "padding": "4px 4px 4px 4px"
  },
  "attributes": {
    "class": "sp-field-quickAction",
    "href": "[$ClientSiteURL]",
    "target": "_blank"
  }
}
1

2 Answers 2

0

Please use the below JSON Formatting:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "a",
  "attributes": {
    "href": "[$ClientSiteURL]",
    "target": "_blank"
  },
  "children": [
    {
      "elmType": "button",
      "txtContent": "Go to the Client Site URL",
      "style": {
        "background-color": "#E6E6FA",
        "color": "#2F4F4F",
        "width": "100%",
        "font-weight": "bold"
      }
    }
  ]
}

enter image description here

enter image description here

1
  • 1
    What's the difference between JSON code I provided in my answer and your answer (except some extra styling)? Dec 2, 2021 at 14:08
5

Use JSON like below to create hyperlink with button:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "attributes": {
    "href": "[$ClientSiteURL]",
    "target": "_blank"
  },
  "style": {
    "text-decoration": "none"
  },
  "children": [
    {
      "elmType": "button",
      "txtContent": "Go to Client Data",
      "style": {
        "cursor": "pointer",
        "width": "100%"
      }
    }
  ]
}

Sample output:

enter image description here

Documentation: Use column formatting to customize SharePoint


Where [$ClientSiteURL] is an internal name of your column which stores hyperlink value in SharePoint list in this format: [$InternalNameOfColumn].

You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?

3
  • I had tried this and it wasn't working - it turns out I had a missing bracket. Thanks for your help and providing me the PROPER coding!!! Dec 2, 2021 at 14:05
  • How to set the value of [$ClientSiteURL] dynamically based on another column value? Mar 19 at 8:44
  • ClientSiteURL is a internal name of another column only - which stores the hyperlink value in the list. You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?. Check updated answer. Mar 19 at 8:48

Your Answer

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

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