Loading Please Wait...

Logo Lynxsia IT Solutions
CSS Links

The links are one of the main element for user interactions. User can click on it and redirect to the desired page.

When styling links, it's important to understand how to make use of pseudo-classes to style their states effectively. It's also important to know how to style links for use in common interface features whose content varies, such as navigation menus and tabs.

Link State

The first thing to understand is the concept of link states — different states that links can exist in. These can be styled using different pseudo-classes

Link: A link that has a destination (normal unvisited), styled using the :link pseudo class.

Visited: A link that has already been visited (exists in the browser's history), styled using the :visited pseudo class.

Hover: A link that is hovered over by a user's mouse pointer, styled using the :hover pseudo class.

Focus: A link that is focused (e.g., moved to by a keyboard user using the Tab key or something similar) — this is styled using the :focus pseudo class.

Active: A link that is activated (e.g., clicked on), styled using the :active pseudo class.

Default State
  • Links are underlined.
  • Unvisited links are blue.
  • Visited links are purple.
  • Hovering a link makes the mouse pointer change to a little hand icon.
  • Focused links have an outline around them
  • Active links are red.
Link must have href attributed to work otherwise normal style is applied and treated as text.
:hover must come after :link and :visited in the CSS definition in order to be effective.
:active must come after :hover in the CSS definition in order to be effective.
					 
        
          /* apply style to all link tag and link state */
          a {
            color: #dea42a;
            outline: none;
          }

          /* unvisited link */
          a:link {
            color: #6900ff;
          }

          /* visited link */
          a:visited {
            color: #a5c300;
          }

          /* focused link */
          a:focus {
            text-decoration: none;
            background: #bae498;
          }

          /* hover link */
          a:hover {
            text-decoration: none;
            background: #cdfeaa;
          }

          /* active link */
          a:active {
            background: #6900ff;
            color: #cdfeaa;
          }
        
      
Button Links With State
					 
        
          <!DOCTYPE html>
          <html>
            <head>
              <style>
                div{ 
                  display: flex;
                  gap: 20px;
                }
                .customBtn{
                  border: 2px solid black;
                  background-color: transparent;
                  color: black;
                  padding: 14px 28px;
                  font-size: 16px;
                  cursor: pointer;
                  border-color: #4836dd;
                  color: #4836dd;
                  text-decoration: none;
                  transition: all 0.25s ease-in-out;
                  border-radius: 8px;
                }
                .customBtn:hover {
                  background-color: #4836dd;
                  color: white;
                }

                .customBtn:focus, .customBtn.focus{
                  box-shadow: 0 0 0 5px rgba(72, 54, 221, 0.2);
                  border-color: #4836dd;
                }

                .customBtn:active, .customBtn.active{
                  background-color: #3a2bb1;
                  border-color: #3a2bb1;
                  color: white;
                }
                .customBtn.disabled{
                  background-color: #a49bee;
                  border-color: #9186eb;
                  color: #6d5ee4;
                  user-select: none;
                  cursor: not-allowed;
                  pointer-events: none;
                }
            </style>
          </head>
          <body>
            <div>
              <a href="#" class="customBtn">Normal</a>
              <a href="#" class="customBtn active">Active</a>
              <a href="#" class="customBtn focus">Focus</a>
              <a href="#" class="customBtn disabled">Disabled</a>
            </div>
          </body>
        </html>
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved