306

I'm attempting to customize the print CSS, and finding that it prints links out with the href value as well as the link.

This is in Chrome.

For this HTML:

<a href="http://www.google.com">Google</a>

It prints:

Google (http://www.google.com)

And I want it to print:

Google
unor
  • 92,415
  • 26
  • 211
  • 360
Chris Gratigny
  • 3,223
  • 2
  • 16
  • 7
  • 1
    Keep in mind WHY every major CSS framework does that - you can't click on paper! So if you're going to deactivate it you should add a list of links at the bottom, such as this: https://alistapart.com/article/improvingprint – Julix Feb 23 '17 at 08:10
  • 1
    That's true, but I think it's better to have control of when and where the link appears. For instance, in my links I want them to appear in the next line after the text, and without parentheses. So I just show the url in the text. – user4052054 Mar 12 '18 at 18:00

7 Answers7

624

Bootstrap does the same thing (... as the selected answer below).

@media print {
  a[href]:after {
    content: " (" attr(href) ")";
  }
}

Just remove it from there, or override it in your own print stylesheet:

@media print {
  a[href]:after {
    content: none !important;
  }
}
Alex Ghiculescu
  • 7,522
  • 3
  • 25
  • 41
  • 18
    `` Mostly posting for myself when I keep coming back to this page, thank you – William Entriken Dec 04 '14 at 16:43
  • 1
    Apparently Foundation does the samething too. – spasticninja Oct 16 '15 at 17:02
  • Looks like **HTML5 Boilerplate** also does this! So I guess I have to override it through code change on my own website, and through Inspector on other websites... – ADTC Nov 01 '16 at 11:28
  • Warning: We had issues where a table sometimes lost the last few rows when printing. Turned out that this rule was the culprit, or at least removing it fixed the issue. Do not know why it had that effect. – Henrik N Mar 29 '17 at 07:44
  • After digging more, I don't think that this was the only factor. While removing it fixed the issue, removing it AND all of Bootstrap print reintroduced the issue… – Henrik N Mar 29 '17 at 08:00
  • 1
    @HenrikN - i think that's related to bootstrap columns floating. using `float:none` where necessary fixed a similar issue for me a few weeks back; might help you, but that's a different issue – Andrew Apr 18 '17 at 19:06
41

It doesn't. Somewhere in your print stylesheet, you must have this section of code:

a[href]::after {
    content: " (" attr(href) ")"
}

The only other possibility is you have an extension doing it for you.

Eric
  • 95,302
  • 53
  • 242
  • 374
29

@media print {
   a[href]:after {
      display: none;
      visibility: hidden;
   }
}

Work's perfect.

JELEWA.de
  • 291
  • 3
  • 3
10

If you use the following CSS

<link href="~/Content/common/bootstrap.css" rel="stylesheet" type="text/css"    />
<link href="~/Content/common/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="~/Content/common/site.css" rel="stylesheet" type="text/css" />

just change it into the following style by adding media="screen"

<link href="~/Content/common/bootstrap.css" rel="stylesheet" **media="screen"** type="text/css" />
<link href="~/Content/common/bootstrap.min.css" rel="stylesheet" **media="screen"** type="text/css" />
<link href="~/Content/common/site.css" rel="stylesheet" **media="screen"** type="text/css" />

I think it will work.

the former answers like

    @media print {
  a[href]:after {
    content: none !important;
  }
}

were not worked well in the chrome browse.

Wang Jijun
  • 326
  • 4
  • 10
5

I encountered a similar problem only with a nested img in my anchor:

<a href="some/link">
   <img src="some/src">
</a>

When I applied

@media print {
   a[href]:after {
      content: none !important;
   }
}

I lost my img and the entire anchor width for some reason, so instead I used:

@media print {
   a[href]:after {
      visibility: hidden;
   }
}

which worked perfectly.

Bonus tip: inspect print preview

Tim Diggins
  • 4,364
  • 3
  • 30
  • 49
TrampGuy
  • 1,737
  • 1
  • 13
  • 9
3

To hide Page url .

use media="print" in style tage example :

<style type="text/css" media="print">
            @page {
                size: auto;   /* auto is the initial value */
                margin: 0;  /* this affects the margin in the printer settings */
            }
            @page { size: portrait; }
</style>

If you want to remove links :

@media print {
   a[href]:after {
      visibility: hidden !important;
   }
}
Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
0

For normal users. Open the inspect window of current page. And type in:

l = document.getElementsByTagName("a");
for (var i =0; i<l.length; i++) {
    l[i].href = "";
}

Then you shall not see the url links in print preview.

Wen Xin
  • 29
  • This is a good solution if you have no control over the source code of the page you are trying to print. – Paddymac Nov 11 '19 at 11:06