Styling CSS Links and Cursor Types: Unvisited, Visited, Hovered, and Active

Posted on : 2023-10-31
Styling CSS Links and Cursor Types: Unvisited, Visited, Hovered, and Active

Share

When it comes to web design, hyperlinks are fundamental elements that allow users to navigate through your website. CSS (Cascading Style Sheets) provides powerful tools to customize the appearance and behavior of these links in various states: unvisited, visited, hovered, and active. In addition to these styling options, it's essential to understand different cursor types that can be applied to links to improve the user experience.

Normal, Unvisited Links

The a:link selector is used to style unvisited links on a webpage. While cursor types are not typically specified within CSS for links, it's essential to consider cursor types to enhance user interaction. For example, setting the cursor to "pointer" makes it clear that the link is clickable.

a:link {
  text-decoration: none; /* Removes the underline */
  color: #0077b5; /* Changes the link color to blue */
  font-weight: bold; /* Makes the text bold */
  cursor: pointer; /* Changes the cursor to a hand pointer on hover */
}

Visited Links

The a:visited selector allows you to style links that users have previously visited. Similar to unvisited links, you can also apply cursor types to visited links to make them more user-friendly.

a:visited {
  color: #4b0082; /* Changes the link color to indigo */
  cursor: pointer; /* Changes the cursor to a hand pointer on hover */
}

Links on Hover

The a:hover selector comes into play when users hover their mouse pointer over links. This interaction serves as a visual cue, indicating that the link is interactive. While not included in the CSS code, you can also customize cursor types to make the user's experience more intuitive. For instance, changing the cursor to "pointer" on hover signals that the link can be clicked.

a:hover {
  text-decoration: underline; /* Adds an underline on hover */
  color: #ff6600; /* Changes the link color to orange */
  cursor: pointer; /* Changes the cursor to a hand pointer on hover */
}

Links When Clicked

The a:active selector is used to style links the moment they are clicked. Again, cursor types can be adjusted during the click event to make the interaction more intuitive. Setting the cursor to "pointer" provides visual confirmation of the link's clickability.

a:active {
  color: #ff0000; /* Changes the link color to red */
  cursor: pointer; /* Changes the cursor to a hand pointer while the link is being clicked */
}

Understanding Cursor Types

In addition to CSS link styling, it's important to have a basic understanding of cursor types that can be used in web design. Here are some commonly used cursor types:

  • auto: The default cursor for the browser, which is usually an arrow.
  • crosshair: A crosshair cursor often used to indicate a selection.
  • default: The standard arrow cursor.
  • e-resize: A cursor with a double-headed arrow pointing horizontally to indicate resizing.
  • help: A cursor with a question mark to indicate help or information.
  • move: A cursor with a four-headed arrow, indicating that something can be moved.
  • n-resize: A cursor with a double-headed arrow pointing vertically to indicate resizing.
  • ne-resize: A cursor with a double-headed arrow pointing diagonally to the top-right to indicate resizing.
  • nw-resize: A cursor with a double-headed arrow pointing diagonally to the top-left to indicate resizing.
  • pointer: The hand pointer cursor, indicating a clickable link or interactive element.
  • progress: A cursor with an hourglass or spinning wheel, indicating a process is in progress.
  • s-resize: A cursor with a double-headed arrow pointing vertically to indicate resizing.
  • se-resize: A cursor with a double-headed arrow pointing diagonally to the bottom-right to indicate resizing.
  • sw-resize: A cursor with a double-headed arrow pointing diagonally to the bottom-left to indicate resizing.
  • text: The I-beam cursor, typically used for text input fields.
  • w-resize: A cursor with a double-headed arrow pointing horizontally to indicate resizing.
  • wait: A cursor with an hourglass, indicating that the user should wait.

Here are the examples for cursor types above. You can use use your mouse on your desktop pc to test them.

auto
crosshair
default
e-resize
help
move
n-resize
ne-resize
nw-resize
pointer
progress
s-resize
se-resize
sw-resize
text
w-resize
wait

 

These cursor types can be applied to various elements on your website, not just links, to provide visual cues and improve the overall user experience. The choice of cursor type should be based on the context and the action you want to convey to your website visitors.