Javatpoint Logo
Javatpoint Logo

CSS Link

Introduction

The textual links are colored and highlighted to provide perceptual attention, like most paintings are framed to enhance their look and for decorating reasons. The HTML/CSS standards specify that clicked hyperlinks be underlined by default. This promotes clickability and engagement with web pages and serves various functions. Examples of online services include E-commerce websites, search engine display sites, communication channels, encyclopedias, news portals, video libraries, index pages, etc.

Furthermore, whether you are a front-end web designer unhappy with the appearance of your custom website owing to non-uniformity in text or if you are attempting to erase the irregularities created by underlined hyperlinks, this article will precisely illuminate the alternatives for you.

What is a Link in CSS?

A link, often known as a hyperlink, is an item that connects online pages or sections within the same web page. Tag in HTML denotes a hyperlink, with the "href" property indicating the destination URL. Furthermore, regardless of the condition of the connection, the HTML standard requires that the textual hyperlink remain highlighted. In all known browsers, links may only have one of four states (unvisited, visited, hover, or active link state) at a time. This common constraint, however, may be overcome with the use of numerous CSS style codes.

As a result, hyperlinks are styled using the CSS attribute. Furthermore, the various states of a link may be stylized by defining pseudo-classes.

We may go from one page to another using links. If visited, links are underlined in blue and purple in their purest form. As a result, even without any CSS coding, links in HTML seem significantly different from plain text.

Link Values by Default

  1. Underlined link
  2. When hovered over, the symbol changes to a hand.
  3. Unvisited links are blue.
  4. Links that have been visited are highlighted in purple.
  5. Active links are shown in red.
  6. An outline surrounds focused links.

But who wants the standard look? Why not personalize the look of links on each web page? Standard style may not always complement the backdrop color or texture. As shown in this post, you can rapidly design the links using CSS in any of these cases. But before we get further into styling, let's look at the various states of CSS links we may design.

Different CSS Link States

CSS links have several states. The states describe how links change as a user interacts with them. For example, before clicking on the link, after clicking, when lingering over it, and so on. Here are the many states of CSS links.

  • Link (a:link): The unvisited condition occurs when the user has not yet clicked on the link.
  • Visited (a:visited): The condition in which the user has at least once viewed the link.
  • Hover (a:hover): The mouse's condition when hovering over a link.
  • Active (a:active): The state in which the link has been clicked but has not yet directed the user to the destination href URL.
  • Focus (a:focus): The state in which the link is focused, such as when pressing the tab key on the keyboard to navigate.

Syntax of CSS Link

The syntax for using CSS links is:

CSS links allow you to use some fundamental CSS characteristics. These characteristics include color, font-family, text-decoration, background-color, etc. The color value can be defined using the color's name, hex code, or RGB value. The text-decoration attribute is used to retain or remove the underline from links. Set the text-decoration property value to 'none' to turn off the underlining. We will utilize these characteristics in all examples to style links in various states. But first, let's construct the HTML code that will be used in all examples.

Code:

Output:

CSS Link

CSS Link Properties

The following are some basic CSS characteristics of links:

1. Color:

The color of the link text may be changed using this CSS property.

Syntax

Example: This example demonstrates the usage of the color property in links.

Output:

CSS Link

2. Font-family:

The font-family property is used to modify the font type of a link.

Syntax:

Example: This example demonstrates the usage of the font-family property in links.

Output:

CSS Link

3. Text-Decoration:

This property removes or adds underlines to/from a link.

Syntax:

Example: This example demonstrates the usage of the text-decoration property in links.

Output:

CSS Link

4. Background-color:

This property is used to specify the color of the link's background.

Syntax:

Example: This example demonstrates the usage of the background-color property in links.

Output:

CSS Link

CSS Link Button

CSS links may also be customized with buttons/boxes customized with buttons/boxes. The following example demonstrates how CSS links may be made into buttons.

Example: This example demonstrates the usage of links as a button.

Output:

CSS Link

Here's a breakdown of all the anchor pseudo-classes used in the preceding example.

  • a:link: It is used to style URLs that have not yet been viewed. It changes the text-decoration to none in this example, which removes the underline that is traditionally associated with links.
  • a:visited: It is used to style previously visited URLs. In this scenario, the color indicates that the link has been followed.
  • a:link: When the mouse pointer hovers over a link, it is styled with a:hover. This example changes the text decoration to underline and the color to purple, resulting in an underlining effect and altering the link color to purple.
  • a:active: This class is used to style links when they are clicked.

The pseudo-classes :hover, :focus, and :active allow us to style items according to how a user interacts with them. Depending on the device, these pseudo-classes become active at different moments (or not at all).

This is why it's critical to specify these styles in the order they commonly occur so the user knows when a new interaction is acknowledged. A user will often hover over an element, bring it to focus, and activate it. So, the easiest approach to arrange your pseudo-class styles is as follows :hover then :focus then :active.


Next TopicCSS Login





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA