skip to main content
Select font family
Select colour theme
Profile picture - Ahmad Ainul Rizki Ahmad Ainul Rizki
Profile logo - Ahmad Ainul RizkiCD
  • Home
  • About me
  • Now
  • Portfolio
  • Blog
  • Components

Anchor tags

An anchor tag is used to link from one page or section of a page to another.

  • Follow me on Twitter twitterlink to twitter profile
  • View my Github profile githublink to github profile
  • View my Codepen profile codepenlink to codepen profile

Link

External link

Incredibly long anchor text link

Anchor tags should:

  • have clear hover and focus states
  • be distinguishable by more than just colour
  • have desctiptive content like "We'd love for you to get in touch with us
  • clearly communicate if they open a new window
  • show the full URL if printed

Anchor tags should not:

  • use non descriptive text like "Click here to get in touch
  • perform an action, for this use a button

Code

Use the tabs to view the anchor tags source code.

Use left and right arrows to navigate between tabs.
  • HTML
  • CSS

HTML

                      
                      
  <p>
    <a href="#" class="anchor">Link</a>
  </p>

  <p>
    <a href="#" class="anchor" rel="noopener" target="_blank">External link</a>
  </p>

  <p>
    <a href="#" class="anchor">Incredibly long anchor text link</a>
  </p>

                    

CSS


  /*
  Anchors
  ----------------------------------- */
:root {
   --colour-focus: hsl(311, 100%, 50%);
}

.footer {
  --colour-focus: hsl(312, 100%, 24%);
}

/* a {
  --link: hsl(230, 60%, 50%);
  --link-visited: hsl(290, 60%, 50%);
  --link-hover: hsl(230, 80%, 60%);
  --link-active: hsl(350, 60%, 50%);
} */

 a,
.anchor {
  transition: all .3s ease-in-out;
  color: currentColor;
  text-decoration: underline;
  /* text-underline-offset: 1px;
  text-decoration-thickness: 1px;
  transition: all .3s ease-in-out; */
  /* padding: 0 .3rem; */
}

a:hover,
.anchor:hover {
  /* outline: dashed 1px var(--colour-pink); */
  text-decoration: none;
}

a:active,
.anchor:active {
  outline-style: dashed;
  outline-color: var(--colour-pink);
  outline-width: 1px;
  background: 
}

a:focus,
.anchor:focus {
  outline: none;
  text-decoration: none;
  background: var(--colour-focus);
  box-shadow: 0 -2px var(--colour-focus), 0 4px var(--colour-black);
}

a:visited,
.anchor:visited {
  outline-style: dashed;
  outline-color: var(--colour-pink);
  outline-width: 1px;
}

.anchor[target=_blank]:after {
  content: ' (opens new window)';
} 

/* Print styles */

@media print {
  
  a,
  .anchor{
    color: #000!important;
  }

  a:before,
  .anchor:before {
    content:" (" attr(href) ") "!important;
    font-size: 0.8rem;
    font-weight: normal;
  }

  a:after ,
  .anchor:after {
    content: '';
  }

} 


                    
Back to all components
  • Home
  • About me
  • Now
  • Portfolio
  • Blog
  • Components
  • Follow me on Twitter twitterlink to twitter profile
  • View my Github profile githublink to github profile
  • View my Codepen profile codepenlink to codepen profile

Proudly powered by Eleventy. Hosted on Netlify, last updated September 15th 2020, at 10:55:44 - privacy.