SharePoint Column Formatting – customize the look of Hyperlink columns and their Display Text

3+

There is nothing wrong with how SharePoint Hyperlink columns display information by default. However, some users believe that the look is too generic, hard to bring attention to, which I myself tend to agree with.

Let’s see how it looks by default:

The issues in my opinion are:

  • the Display Text is grey and no different than any other column
  • if Display Text needs to always be the same (e.g. CLICK HERE), then it has to be typed in that way in every single list item.

We will address both issues.


1. KEEP THE ORIGINAL DISPLAY TEXT AND CHANGE THE LOOK

The following JSON code is applied to both Hyperlink columns:

{
	"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
	"elmType": "a",
	"txtContent": "@currentField.desc",
	"style": {
		"color": "red",
		"font-weight": "bold"
	},
	"attributes": {
		"target": "_blank",
		"href": "@currentField"
	}
}


2. SHOW PREDEFINED DISPLAY TEXT AND CHANGE THE LOOK

The following JSON code is applied to both Hyperlink columns:

{
	"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
	"elmType": "a",
	"txtContent": "CLICK HERE",
	"style": {
		"color": "blue",
		"font-weight": "bold"
	},
	"attributes": {
		"target": "_blank",
		"href": "@currentField"
	}
}

3+

This Post Has 11 Comments

  1. Jennifer

    How do you adjust the code so that it does not apply the “Click Here” for cells that are blank?

    0
    1. Pavel Bludov

      Hi Jennifer!
      Replace this line:
      “txtContent”: “CLICK HERE”,
      with this one:
      “txtContent”: “=if(@currentField == ”, ”, ‘CLICK HERE’)”,

      PS. When copying text from my comment please pay attention to single and double quotes – they might not work as they appear to be “curly” rather than “straight”. They will break your JSON.
      Also the quotes here ”, ”, are single quotes next to each other, they are not double quotes.

      Please let me know if any issues. Stay healthy and safe!

      0
  2. Silviu

    This is a great help, thank you. What do I have to change in the code so that it does not underline the links?

    0
    1. Pavel Bludov

      Hi Silviu,
      What you are looking for is “text-decoration”: “none”
      So your code would look similar to this:
      {
      “$schema”: “http://columnformatting.sharepointpnp.com/columnFormattingSchema.json”,
      “elmType”: “a”,
      “txtContent”: “@currentField.desc”,
      “style”: {
      “color”: “red”,
      “font-weight”: “bold”,
      “text-decoration”: “none”
      },
      “attributes”: {
      “target”: “_blank”,
      “href”: “@currentField”
      }
      }

      0
  3. Dennis

    Hi,

    Is there a way to have it show the title of a page in the txtContent?

    0
    1. Pavel Bludov

      Hi Dennis,
      What title of a page?
      You can reference any column that is in the view.
      Thanks!

      0
  4. Dennis

    Hi Pavel,

    Sorry for not being more clear. I meant the title of the page the link points to in the column. For instance in the HTML for this page the title says “SharePoint Column Formatting – customize the look of Hyperlink columns and their Display Text – Office 365 Basics”. I would like that to show instead of the link. Is that possible? Thanks.

    0
    1. Pavel Bludov

      If I understood you correctly, I don’t think it’s possible unless you populate that value into one of the columns on your SharePoint. Populating could be possible through an HTTP Request action in Power Automate.

      0
      1. Dennis

        OK, thanks for the update. I’ll go the Power Automate route.

        0
  5. jeff

    Is there a way to do this while formatting the View? @currentfield always references the $Title, and all I can get is the description when using the field name, I can’t reference the URL.

    0
    1. Pavel Bludov

      Hi Jeff,
      Using a view formatting I was able to reference a different column no problem:
      Its display text – “txtContent”: “[$testlink.desc]”
      Its link – “href”: “[$testlink]”
      Thanks!

      0

Leave a Reply