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 4 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

Leave a Reply