2021 Solution
a[href]:not(:where(
/* exclude hash only links */
[href^="#"],
/* exclude javascript only links */
[href^="javascript:" i],
/* exclude relative but not double slash only links */
[href^="/"]:not([href^="//"]),
/* domains to exclude */
[href*="//stackoverflow.com"],
/* subdomains to exclude */
[href*="//meta.stackoverflow.com"],
)):after {
content: '';
}
<strong>Internal sites:</strong>
<br>Lorem <a href="http://stackoverflow.com">http://stackoverflow.com</a> ipsum
<br>Lorem <a href="/a/5379820">/a/5379820</a> ipsum
<br>Lorem <a href="//stackoverflow.com/a/5379820">//stackoverflow.com/a/5379820</a> ipsum
<br>Lorem <a href="http://stackoverflow.com/a/5379820">http://stackoverflow.com/a/5379820</a> ipsum
<br>Lorem <a href="https://stackoverflow.com/a/5379820">https://stackoverflow.com/a/5379820</a> ipsum
<br>Lorem <a href="https://meta.stackoverflow.com/">https://meta.stackoverflow.com/</a> ipsum
<br>Lorem <a href="ftp://stackoverflow.com">ftp://stackoverflow.com</a> ipsum
<br><br>
<strong>External sites:</strong>
<br>Lorem <a href="ftp://google.com">ftp://google.com</a> ipsum
<br>Lorem <a href="https://google.com">https://google.com</a> ipsum
<br>Lorem <a href="http://google.com">http://google.com</a> ipsum
<br>Lorem <a href="https://www.google.com/search?q=stackoverflow">https://www.google.com/search?q=stackoverflow</a>
<br>Lorem <a href="//www.google.com/search?q=stackoverflow">//www.google.com/search?q=stackoverflow</a>
<br><br>
<strong>Other anchor types</strong>
<br>Lorem <a>no-href</a> ipsum
<br>Lorem <a href="#hash">#hash</a> ipsum
<br>Lorem <a href="javascript:">javascript:</a> ipsum
2014 Solution
Using some special CSS syntax you can easily do this. Here is one way that should work for both the HTTP and HTTPS protocols:
a[href^="http://"]:not([href*="stackoverflow.com"]):after,
a[href^="https://"]:not([href*="stackoverflow.com"]):after {
content: '';
}
Answer from Shaz on Stack Overflow2021 Solution
a[href]:not(:where(
/* exclude hash only links */
[href^="#"],
/* exclude javascript only links */
[href^="javascript:" i],
/* exclude relative but not double slash only links */
[href^="/"]:not([href^="//"]),
/* domains to exclude */
[href*="//stackoverflow.com"],
/* subdomains to exclude */
[href*="//meta.stackoverflow.com"],
)):after {
content: '';
}
<strong>Internal sites:</strong>
<br>Lorem <a href="http://stackoverflow.com">http://stackoverflow.com</a> ipsum
<br>Lorem <a href="/a/5379820">/a/5379820</a> ipsum
<br>Lorem <a href="//stackoverflow.com/a/5379820">//stackoverflow.com/a/5379820</a> ipsum
<br>Lorem <a href="http://stackoverflow.com/a/5379820">http://stackoverflow.com/a/5379820</a> ipsum
<br>Lorem <a href="https://stackoverflow.com/a/5379820">https://stackoverflow.com/a/5379820</a> ipsum
<br>Lorem <a href="https://meta.stackoverflow.com/">https://meta.stackoverflow.com/</a> ipsum
<br>Lorem <a href="ftp://stackoverflow.com">ftp://stackoverflow.com</a> ipsum
<br><br>
<strong>External sites:</strong>
<br>Lorem <a href="ftp://google.com">ftp://google.com</a> ipsum
<br>Lorem <a href="https://google.com">https://google.com</a> ipsum
<br>Lorem <a href="http://google.com">http://google.com</a> ipsum
<br>Lorem <a href="https://www.google.com/search?q=stackoverflow">https://www.google.com/search?q=stackoverflow</a>
<br>Lorem <a href="//www.google.com/search?q=stackoverflow">//www.google.com/search?q=stackoverflow</a>
<br><br>
<strong>Other anchor types</strong>
<br>Lorem <a>no-href</a> ipsum
<br>Lorem <a href="#hash">#hash</a> ipsum
<br>Lorem <a href="javascript:">javascript:</a> ipsum
2014 Solution
Using some special CSS syntax you can easily do this. Here is one way that should work for both the HTTP and HTTPS protocols:
a[href^="http://"]:not([href*="stackoverflow.com"]):after,
a[href^="https://"]:not([href*="stackoverflow.com"]):after {
content: '';
}
This way shows external links ALA Wikipedia:
a[href^="http"]:after {
content: " " url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAVklEQVR4Xn3PgQkAMQhDUXfqTu7kTtkpd5RA8AInfArtQ2iRXFWT2QedAfttj2FsPIOE1eCOlEuoWWjgzYaB/IkeGOrxXhqB+uA9Bfcm0lAZuh+YIeAD+cAqSz4kCMUAAAAASUVORK5CYII=);
}
An example can be found here: http://jsfiddle.net/ZkbKp/
Adding external css file to html doc
External file link explanation
Adding an "external" icon to target _blank links
Can I get a little help with external CSS?
I think you should explain more about what you are trying to accomplish, what the result is from your code, and what about it is incorrect from what the desired result should be.
More on reddit.comVideos
I feel stupid and like I have taking 3 steps back in my learning. I am trying to figure out the 3 different implementations of css. Doing External now. Just trying this super simple code, the colors did not show up in the browser like they did on w3schools.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Is it because I don't have a css file on my computer? Do I need to download one? Copy and paste from somewhere? I don't get it. I prefer building with the css and html on the same document because I haven't learned how to do anything else yet. I have been able to follow tutorials fine but for some reason, now it's not clicking.