<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Barbara Szott</title>
    <description>The latest articles on DEV Community by Barbara Szott (@barbaraszott).</description>
    <link>https://dev.to/barbaraszott</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F50025%2Ff509bee4-41e8-4e16-be91-d12a968d491e.jpg</url>
      <title>DEV Community: Barbara Szott</title>
      <link>https://dev.to/barbaraszott</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/barbaraszott"/>
    <language>en</language>
    <item>
      <title>Drop the anchooor! Short story about hyperlinks, their styling and states, and why LVHA rule is important</title>
      <dc:creator>Barbara Szott</dc:creator>
      <pubDate>Mon, 13 May 2019 12:29:14 +0000</pubDate>
      <link>https://dev.to/barbaraszott/drop-the-anchooor-short-story-about-hyperlinks-their-styling-and-states-and-why-lvha-rule-is-important-2d9p</link>
      <guid>https://dev.to/barbaraszott/drop-the-anchooor-short-story-about-hyperlinks-their-styling-and-states-and-why-lvha-rule-is-important-2d9p</guid>
      <description>&lt;h1&gt;
  
  
  I am sure you know what anchors are!
&lt;/h1&gt;

&lt;p&gt;They are links, or &lt;a href="https://en.wikipedia.org/wiki/Hyperlink" rel="noopener noreferrer"&gt;hyperlinks&lt;/a&gt; to be more exact. They are Internet's basic construction material - they make the Internet information highway. We can travel through them and teleport to a different part of Web in a blink. We all know what they are. Right? Right. But just to be 100% clear - in HTML &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tags are something different. &lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; element
&lt;/h2&gt;

&lt;p&gt;I'm not going to write a lot about it. According to W3C:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag defines a link between a document and an external resource and is used to link to external style sheets.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Also:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The  element is an empty element, it contains attributes only.&lt;br&gt;
This element goes only in the head section, but it can appear any number of times.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In HTML the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag has no end tag. Default styling in all browsers is &lt;code&gt;display: none&lt;/code&gt;. Most commonly you will see something like this in head section of HTML document:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"styles.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to learn more about &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; I encourage you to visit for example &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link" rel="noopener noreferrer"&gt;MDN Documentation&lt;/a&gt;. But for now - let's get back to business.&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; element
&lt;/h2&gt;

&lt;p&gt;This is the main character of this story. Famous anchor element, that creates a hyperlink to other websites, files, e-mail addresses or just to other location within the same page. As opposed to the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; it does need ending tag. It can have a whole bunch of attributes - the most widely known is &lt;code&gt;href&lt;/code&gt;. Without it our anchor won't lead us anywhere.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Check out my &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"http://twitter.com/BarbaraSzott"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Twitter&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The other very often used attribute is &lt;code&gt;target&lt;/code&gt; - default value is &lt;code&gt;_self&lt;/code&gt;, which means "load content here, in the same browsing context as the current one"; other commonly used value is &lt;code&gt;_blank&lt;/code&gt; - "load content in the new browsing context", which usually means a new tab in the browser. I'm gonna stop here for a second to remind you about &lt;code&gt;rel="noopener"&lt;/code&gt;. You should consider adding this attribute while using &lt;code&gt;target="_blank"&lt;/code&gt;, especially for untrusted sources. Why?&lt;/p&gt;

&lt;p&gt;Mostly for &lt;strong&gt;safety&lt;/strong&gt; reasons - if &lt;code&gt;rel="noopener"&lt;/code&gt; is used we avoid exploitation of &lt;code&gt;window.opener&lt;/code&gt; API. Thanks to that when new window is created after clicking a link, potentially malicious code running on the new window won't access previous window through &lt;code&gt;window.opener&lt;/code&gt; attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"http://someoneswebsite.com"&lt;/span&gt; &lt;span class="na"&gt;target=&lt;/span&gt;&lt;span class="s"&gt;"_blank"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"noopener"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some website&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ufff, that part was difficult! If you are interested read more about &lt;code&gt;noopener&lt;/code&gt; &lt;a href="https://mathiasbynens.github.io/rel-noopener/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Styling links - let's dive in!
&lt;/h2&gt;

&lt;p&gt;Take a look at how simple link with default styling looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fe9m3z0o1xml8e48ytsa3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fe9m3z0o1xml8e48ytsa3.png" alt="image of link with default styling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, it is blue and underlined. Purple, if visited:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fexslw1wd7n43gwht2ryj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fexslw1wd7n43gwht2ryj.png" alt="image of visited link with default styling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nonetheless, typically this is not the appearance we want. Luckily for us - styling links is as easy as styling any other element. We can change color, add background color, borders, change font etc. Take a look at what is happening after changing some simple CSS for our &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#00acee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="m"&gt;#008abe&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* remove underline */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...and the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzpd4mbnpdgoaivcngk1t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzpd4mbnpdgoaivcngk1t.png" alt="styled link"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nothing too fancy. We can play around with it however we want. The fun begins with introduction of &lt;strong&gt;link states&lt;/strong&gt;, and there are (basically) &lt;strong&gt;four&lt;/strong&gt; of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Link states
&lt;/h2&gt;

&lt;h3&gt;
  
  
  :link
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;:link&lt;/code&gt; state is &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes" rel="noopener noreferrer"&gt;CSS pseudo-class&lt;/a&gt; that basically means "unvisited". It matches every unvisited element with &lt;code&gt;href&lt;/code&gt; attribute (so not only &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But why use this pseudo-class, why can't I just style my anchor element? It's gonna apply either way, so what's the purpose of this state..?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There might be situations when you just want some general styling for anchor elements and special ones for unvisited links with, lets say, different classes (so different styling). On top of that - &lt;code&gt;:link&lt;/code&gt; attribute only matches elements with &lt;code&gt;href&lt;/code&gt; attribute. According to &lt;a href="https://www.w3.org/TR/2016/REC-html51-20161101/textlevel-semantics.html#the-a-element" rel="noopener noreferrer"&gt;W3C spec&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If the &lt;code&gt;a&lt;/code&gt; element has no &lt;code&gt;href&lt;/code&gt; attribute, then the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element’s contents.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So it's seems valid to use anchors without &lt;code&gt;href&lt;/code&gt;. Besides, in the galaxy far, far away, before HTML5 was introduced, anchors could have had &lt;code&gt;name&lt;/code&gt; attribute and no &lt;code&gt;href&lt;/code&gt; attribute for on-site navigation. So we could do something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#aboutUs"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click here to know us better!&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- some code... --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"aboutUs"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Something about us&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now this technique is considered obsolete and should not be used&lt;/strong&gt; - we can simply use IDs to do the same thing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#aboutUs"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click here to know us better!&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- some code... --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"aboutUs"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Something about us&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  :visited
&lt;/h3&gt;

&lt;p&gt;This state is self-explanatory - it selects links that already have been visited by current browser. We can add some styles for &lt;code&gt;:visited&lt;/code&gt; to help users tell the difference between links they have or haven't clicked. Sounds simple - there is a catch though. It's again about &lt;strong&gt;security&lt;/strong&gt; - listen carefully what &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Privacy_and_the_:visited_selector" rel="noopener noreferrer"&gt;MDN&lt;/a&gt; says about it:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before about 2010, the CSS &lt;code&gt;:visited&lt;/code&gt; selector allowed websites to uncover a user's browsing history and figure out what sites the user had visited. This was done through &lt;code&gt;window.getComputedStyle&lt;/code&gt; and other techniques. This process was quick to execute, and made it possible not only to determine where the user had been on the web, but could also be used to guess a lot of information about the user's identity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I've got goose bumps. For Pete's sake, it's just a link's state we want to style, and all of the sudden there is this issue. Fortunately it's been few years and now browsers take a good care of us. Nowadays the &lt;code&gt;window.getComputedStyle&lt;/code&gt; method (and similar functions, like &lt;code&gt;document.querySelector&lt;/code&gt;) will always return values adequate for unvisited links or page. End of topic, you won't get any styles with these method for &lt;code&gt;:visited&lt;/code&gt; links.&lt;/p&gt;

&lt;p&gt;So what about styling? Can we do what we want? Not exactly - we have limited options here, and they include: &lt;code&gt;color&lt;/code&gt;, &lt;code&gt;background-color&lt;/code&gt;, &lt;code&gt;border-color&lt;/code&gt;, &lt;code&gt;outline-color&lt;/code&gt; and the color parts of the &lt;code&gt;fill&lt;/code&gt; and &lt;code&gt;stroke&lt;/code&gt; attributes. What's more - you can &lt;strong&gt;only&lt;/strong&gt; change these styles if the link already has these properties set for its unvisited version. Let's see how it works...&lt;/p&gt;

&lt;p&gt;For simplicity I'm going to separate general &lt;code&gt;a&lt;/code&gt; styles from its states' styles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...now the states:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:link&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;purple&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;yellow&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:visited&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;yellow&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;purple&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything works just fine - unvisited link is purple with yellow background and visited is yellow with purple background, just as we wanted it to be.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmw303doqvp9pl3um7k62.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmw303doqvp9pl3um7k62.png" alt="styled visited and unvisited link"&gt;&lt;/a&gt;&lt;br&gt;
But what if we decide that only visited link should have background color..?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:link&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;purple&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:visited&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;yellow&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;purple&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You guessed right - it's not gonna work.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6l53yda34w6d2poffxn7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6l53yda34w6d2poffxn7.png" alt="visited link not styled cause unvisited version doesn't contain property"&gt;&lt;/a&gt;&lt;br&gt;
Color will be different, but background-color won't apply because unvisited version of that link doesn't have that property. If you gonna do opposite thing styles from &lt;code&gt;:link&lt;/code&gt; will apply to unvisited link as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:link&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;purple&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;orange&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:visited&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;yellow&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvgf6ai1jodxwuvi2p1hl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvgf6ai1jodxwuvi2p1hl.png" alt="visited link styled as unvisited version"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What I've also found interesting here - if you don't specify border color it's gonna be borrowed from &lt;code&gt;color&lt;/code&gt; property. &lt;em&gt;(This applies to other elements as well)&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* some styles... */&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:link&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;purple&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:visited&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;orange&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Faeogpu2zys63o3yqkdh8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Faeogpu2zys63o3yqkdh8.png" alt="border color borrowed from color property"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No matter how you style your unvisited and visited links, have always in mind that they should be easily distinguished from each other. &lt;/p&gt;

&lt;h3&gt;
  
  
  :hover
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;:hover&lt;/code&gt; is used to select elements when you mouse over them. It can be used not only on links but on all elements. It's important to remember that it might not work properly on touchscreens though. According to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:hover" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;:hover&lt;/code&gt; pseudo-class is problematic on touchscreens. Depending on the browser, the :hover pseudo-class might never match, match only for a moment after touching an element, or continue to match even after the user has stopped touching and until the user touches another element. Web developers should make sure that content is accessible on devices with limited or non-existent hovering capabilities.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  :active
&lt;/h3&gt;

&lt;p&gt;This pseudo-class represents element that was activated (usually by the click). Link (or anything else, cause any element can have &lt;code&gt;:active&lt;/code&gt; pseudo-class) is active only for a fraction of a second, but if we change appearance of this state we will give visual feedback that element was indeed clicked.&lt;/p&gt;

&lt;h2&gt;
  
  
  LVHA rule
&lt;/h2&gt;

&lt;p&gt;Now is a good time to remind you about very important aspect of our beloved CSS - &lt;strong&gt;specificity&lt;/strong&gt;. (&lt;em&gt;If your are not familiar with that topic - there is nice article about it on &lt;a href="https://css-tricks.com/specifics-on-css-specificity/" rel="noopener noreferrer"&gt;CSS Tricks&lt;/a&gt;&lt;/em&gt;) Every selector has one. If two selectors apply to the same element, the one with higher specificity wins, and if you add two declarations that points at the same element in your stylesheet with the same weight - the CSS will choose the latter. This is how the cascade works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;         &lt;span class="c"&gt;/* specificity = 1 */&lt;/span&gt;
&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:link&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;    &lt;span class="c"&gt;/* specificity = 1,1 */&lt;/span&gt;
&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:visited&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c"&gt;/* specificity = 1,1 */&lt;/span&gt;
&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;   &lt;span class="c"&gt;/* specificity = 1,1 */&lt;/span&gt;
&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:active&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;  &lt;span class="c"&gt;/* specificity = 1,1 */&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's why order is important, especially for &lt;code&gt;:hover&lt;/code&gt; and &lt;code&gt;:active&lt;/code&gt; pseudo-classes. The other thing that you can see here - selector with pseudo-class has higher specificity, so styles from &lt;code&gt;a:link&lt;/code&gt; might override these from &lt;code&gt;a&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you want you can style differently &lt;code&gt;:hover&lt;/code&gt; for a visited link - just have in mind higher specificity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:visited:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c"&gt;/* specificity = 1,2 */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1.&lt;code&gt;:link&lt;/code&gt; will be overridden by any subsequent link-related pseudo-class&lt;br&gt;
2.&lt;code&gt;:hover&lt;/code&gt; &lt;strong&gt;must&lt;/strong&gt; come after &lt;code&gt;:link&lt;/code&gt; and &lt;code&gt;:visited&lt;/code&gt;&lt;br&gt;
3.&lt;code&gt;:active&lt;/code&gt; &lt;strong&gt;must&lt;/strong&gt; go as a last one (otherwise it will be always overridden)&lt;/p&gt;

&lt;p&gt;LVHA stands for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;L - &lt;code&gt;:link&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;V - &lt;code&gt;:visited&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;H - &lt;code&gt;:hover&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A - &lt;code&gt;:active&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's also easy to remember as a &lt;b&gt;L&lt;/b&gt;O&lt;b&gt;V&lt;/b&gt;E-&lt;b&gt;HA&lt;/b&gt;TE rule. Using this order is considered &lt;strong&gt;best practice&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;target="_blank"&lt;/code&gt; should always go with &lt;code&gt;rel="noopener'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Visited and unvisited links should be easily distinguished - please remember not only about aesthetics but also (mostly) about readability, especially for users with impaired vision&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:visited&lt;/code&gt; pseudo-class have limited styling (&lt;code&gt;color&lt;/code&gt;, &lt;code&gt;background-color&lt;/code&gt;, &lt;code&gt;border-color&lt;/code&gt;, &lt;code&gt;outline-color&lt;/code&gt; and the color parts of the &lt;code&gt;fill&lt;/code&gt; and &lt;code&gt;stroke&lt;/code&gt; attributes)&lt;/li&gt;
&lt;li&gt;Styles for &lt;code&gt;:visited&lt;/code&gt; will only apply if unvisited version of that link also have them&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;:hover&lt;/code&gt; pseudo-class can be problematic on touchscreens&lt;/li&gt;
&lt;li&gt;Styling &lt;code&gt;:active&lt;/code&gt; state gives user visual feedback that something really was clicked&lt;/li&gt;
&lt;li&gt;LOVE-HATE rule&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope you had fun reading this article - I sure did writing it. It is my first tech-post - hope to see some feedback from you! Cheers :)&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
