44

I want to format the default style for text links—currently the color is blue & are underlined.

Is this possible? And if yes, how can I do it?

0

4 Answers 4

12

I just published a free add-on for precisely this task. It's called Link Style, and is available here.

enter image description here

2
  • thanks, very helpful. To clarify for future readers, it doesn't (currently) work with live updating but needs applying to the whole doc periodically/at the end Commented Jan 16, 2020 at 11:56
  • 1
    Doesn't work in 2023
    – dylanh724
    Commented Aug 28, 2023 at 7:51
12

It does not appear to be possible to update the default style for links in your Google doc. This is because Google docs does not treat links as styles. This is understandable, as a link might be applied within text formatted with any other style (e.g., Heading 1, normal text, etc.)

If you try highlighting a link and checking the context menu, note that the option is given to Update 'Normal Text' to match. This indicates that the style of the text is designated exclusively as 'Normal Text' (i.e., does not have a link style).

style menu

Workaround to remove link underlines

I really wanted to be able to change the default for links in the body text to prevent them being underlined. I realise that underlining links is a usability plus online, but aesthetically I felt that it often ruined the flow of a body of text within a document. My workaround is as follows.

If you do not use underlines anywhere else*

  • After writing your document, select all text
  • underline
  • remove underline

This will remove underlines from all text in the document, including links.

If you want to retain underlines elsewhere (e.g., headings, tables)

  • Select a paragraph of Normal Text
  • Underline
  • Right click (ctrl-click on Mac) the selected text
  • Update 'Normal Text' to match
  • Remove underline
  • Update 'Normal Text' to match

This will remove underlines from all Normal Text, including links. You could alternatively use this to change the colour of links to the same as the body text, but you would have to leave the underlines in place, otherwise there would be no clue that the links were there.

2

I came across the same problem. All you need to do is alter the colour of the text the same way you would normal text.

Google doesn't seem to mind if it's a link or not.

1
  • 1
    This answer does not answer the question; only stating the obvious - OP is looking for setting the default style.
    – dylanh724
    Commented Aug 28, 2023 at 7:54
1

I appreciate the solution by DavidR.

Below is a container-bound Google Apps Script that performs similar functions and can be added to your Google Doc.

Instructions

  1. Open your Google Docs file

  2. Open the code editor by clicking on Extensions > Apps Script.
    Google Apps Script

  3. Clear the existing code from the editor and paste the following script the click Save:

    function formatHyperlinks() {
      var body = DocumentApp.getActiveDocument().getBody();
      var searchResult = body.findText('.');
      var linkColor = '#999999';
    
      while (searchResult !== null) {
        var element = searchResult.getElement();
        var startOffset = searchResult.getStartOffset();
        var endOffset = searchResult.getEndOffsetInclusive();
    
        if (element.asText().getLinkUrl(startOffset) !== null) {
          var text = element.asText();
          text.setForegroundColor(startOffset, endOffset, linkColor);
           text.setUnderline(startOffset, endOffset, false);
        }
    
        searchResult = body.findText('.', searchResult);
      }
    }
    
    function onOpen() {
      var ui = DocumentApp.getUi();
      ui.createMenu('Auto format')
         .addItem('Format hyperlinks', 'formatHyperlinks')
         .addToUi();
     }
    
  4. Optionally, edit the script name.

  5. You can run the script from the editor or use the "Format hyperlinks" menu item in the new "Auto format" menu the script adds to the document.
    Run command

  6. The first time you run your script you will be presented with an authorization pop-up.
    Authorization

    1. Click Review permissions
    2. Then, select your Google account
    3. You'll then be presented with another warning
      Warning
    4. Cick Advanced and then click the link at the bottom labeled Go to [your_project_name] (unsafe).
    5. Performing this authorization is necessary because the script requires certain permissions to modify the document on your behalf.

A bit of explanation about the functions:

  • The formatHyperlinks function searches for links and changes the linkColor and removes the underline. You can change the color of the links by altering the #999999 value to a HEX color value of your choosing. You can find the HEX value in Google Docs when you change text color and select 'Custom'.
  • If you don't want it to remove the underline remove text.setUnderline(startOffset, endOffset, false); from the code.
  • The onOpen function adds a menu item to make it easy to execute
    the formatHyperlinks function. The menu item is added when the document is opened so you will need to reopen or refresh the document after saving the script the first time. It also appears if you used the Run command to execute the onOpen function (see step 5).
    enter image description here
1
  • Nice job. If you adapted the script from somewhere please include attribution. If not please note that you are the author
    – Blindspots
    Commented Oct 19 at 3:21

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