The Wayback Machine - https://web.archive.org/web/20241012021727/https://www.geeksforgeeks.org/css-links/
Open In App

CSS Links

Last Updated : 23 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

A link is a connection from one web page to another web page. CSS property can be used to style the links in various different ways.
States of Link: Before discussing CSS properties, it is important to know the states of a link. Links can exist in different states and they can be styled using pseudo-classes.

There are four states of links given below: 

  • a:link => This is a normal, unvisited link.
  • a:visited => This is a link visited by user at least once
  • a:hover => This is a link when mouse hovers over it
  • a:active => This is a link that is just clicked.

Syntax: 

a:link {
    color:color_name;
}

color_name can be given in any format like color name (green), HEX value (#5570f0) or RGB value rgb(25, 255, 2). There is another state ‘a:focus’ which is used to focused when a user uses the tab key to navigate through the links. 

The default value of links: 

  • By default the links created are underlined.
  • When the mouse is hovered above a link, it changes to a hand icon.
  • Normal/unvisited links are blue.
  • Visited links are colored purple.
  • Active links are colored red.
  • When a link is focused, it has an outline around it.

Example: This example shows the basic use of links in CSS.

html
<!DOCTYPE html>
<html>

<head>
    <title>CSS links</title>
    <style>
        p {
            font-size: 25px;
            text-align: center;
        }
    </style>
</head>

<body>
    <p>
        <a href="https://www.geeksforgeeks.org/">
            GeeksforGeeks Simple Link
        </a>
    </p>
</body>

</html>

Output: 

links

GIF Output showing the appearance of links in different states using CSS

CSS Properties of Links: Some basic CSS properties of links are given below: 

  • color
  • font-family
  • text-decoration
  • background-color

color: This CSS property is used to change the color of the link text. 

Syntax:

a {
    color: color_name;
}

Example: This example shows the use of the color property in links.

html
<!DOCTYPE html>
<html>

<head>
    <title>Link color property</title>
    <style>
        p {
            font-size: 20px;
            text-align: center;
        }

        /*unvisited link will appear green*/
        a:link {
            color: red;
        }

        /*visited link will appear blue*/
        a:visited {
            color: blue;
        }

        /*when mouse hovers over link it will appear orange*/
        a:hover {
            color: orange;
        }

        /*when the link is clicked, it will appear black*/
        a:active {
            color: black;
        }
    </style>
</head>

<body>
    <p>
        <a href="https://www.geeksforgeeks.org/">
            GeeksforGeeks
        </a>
        This link will change colours with different states.
    </p>
</body>

</html>

Output: 



statee

GIF Output



font-family: This property is used to change the font type of a link using font-family property. 

Syntax: 

a {
    font-family: "family name";
}

Example: This example shows the use of the font-family property in links.

html
<!DOCTYPE html>
<html>

<head>
    <style>
        /*Initial link font family arial*/
        a {
            font-family: Arial;
        }

        p {
            font-size: 30px;
            text-align: center;
        }

        /*unvisited link font family*/
        a:link {
            color: Arial;
        }

        /*visited link font family*/
        a:visited {
            font-family: Arial;
        }

        /*when mouse hovers over it will change to times new roman*/
        a:hover {
            font-family: Times new roman;
        }

        /*when the link is clicked, it will changed to Comic sans ms*/
        a:active {
            font-family: Comic Sans MS;
        }
    </style>
</head>

<body>
    <p>
        <a href="https://www.geeksforgeeks.org/" id="link">
            GeeksforGeeks
        </a>
        a Computer Science Portal for Geeks.
    </p>
</body>

</html>

Output: 


es

GIF Output



Text-Decoration: This property is basically used to remove/add underlines from/to a link. 

Syntax: 

a {
    text-decoration: none;
}

Example: This example shows the use of the text-decoration property in links.

html
<!DOCTYPE html>
<html>

<head>
    <title>Text decoration in link</title>
    <style>
        /*Set the font size for better visibility*/
        p {
            font-size: 2rem;
        }

        /*Removing underline using text-decoration*/
        a {
            text-decoration: none;
        }

        /*underline can be added using
        text-decoration:underline;
        */
    </style>
</head>

<body>
    <p>
        <a href="https://www.geeksforgeeks.org/" id="link">
            GeeksforGeeks
        </a>
        a Computer Science Portal for Geeks.
    </p>
</body>

</html>

Output: 


abc

GIF Output



background-color: This property is used to set the background color of the link. 

Syntax: 

a {
    background-color: color_name;
}

Example: This example shows the use of the background-color property in links.

html
<!DOCTYPE html>
<html>

<head>
    <title>background color</title>
    <style>
        /*Setting font size for better visibility*/
        p {
            font-size: 2rem;
        }

        /*Designing unvisited link button*/
        a:link {
            background-color: powderblue;
            color: green;
            padding: 5px 5px;
            text-decoration: none;
            display: inline-block;
        }

        /*Designing link button when mouse cursor hovers over it*/
        a:hover {
            background-color: green;
            color: white;
            padding: 5px 5px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
        }
    </style>
</head>

<body>
    <p>
        <a href="https://www.geeksforgeeks.org/" id="link">
            GeeksforGeeks
        </a>
        a Computer Science Portal for Geeks.
    </p>
</body>

</html>

Output: 


pp

GIF Output



CSS Link Button: CSS links can also be styled using buttons/boxes. The following example shows how CSS links can be designed as buttons. 

Example: This example shows the use of links as a button.

html
<!DOCTYPE html>
<html>

<head>
    <title>Link button</title>
    <style>
        /*Setting font size for better visibility*/
        p {
            font-size: 2rem;
        }

        a {
            background-color: green;
            color: white;
            padding: 5px 5px;
            border-radius: 5px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
        }
    </style>
</head>

<body>
    <p>
        <a href="https://www.geeksforgeeks.org/" id="link">
            GeeksforGeeks
        </a>
        a Computer Science Portal for Geeks.
    </p>
</body>

</html>

Output: 


giff

GIF Output

CSS Links- FAQs

How to style links in CSS?

Links are styled using the a selector and various pseudo-classes (:link, :visited, :hover, :active).

What is the :link pseudo-class?

The :link pseudo-class targets links that have not been visited. Example: a:link { color: blue; }.

What is the :visited pseudo-class?

The :visited pseudo-class targets links that have been visited. Example: a:visited { color: purple; }.

What is the :hover pseudo-class?

The :hover pseudo-class styles links when the mouse hovers over them. Example: a:hover { color: red; }.

What is the :active pseudo-class?

The :active pseudo-class styles links when they are being clicked. Example: a:active { color: green; }.



Previous Article
Next Article

Similar Reads

Difference between normal links and active links
Websites are designed to point you to different resources. You can move from one website to another through links. Links help you to get information from different resources. Links are established in simple HTML web pages through <a> tag.Links are categorized into three types. Typically a Link is displayed in three different colors based on t
2 min read
How to create Right Aligned Menu Links using HTML and CSS ?
The right-aligned menu links are used on many websites. Like hotels website that contains lots of options in the menu section but in case of emergency to make contact with them need specific attention. In that case, you can put all the menu options on the left side of the navigation bar and display contact us option on the right side of the bar. Th
3 min read
How to create animated banner links using HTML and CSS?
Links are one of the most important parts of any component that is used in website making. Almost every component had some form of links in it. A common example is a menu/nav-bar. All we see is some button like home, about, etc. but under the hood they all are links. Sometimes there comes a situation where you don't want to wrap the link inside a b
2 min read
Primer CSS Marketing Links
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, an
2 min read
How to Display the file format of links using CSS ?
In this article, we will explain the approach to display the file formats on a webpage. Many times while browsing, we need to download a document file but in PDF format, however, a problem might occur that multiple links of downloading the file are there, but each link contains different file formats. One may contain a document file and another may
2 min read
How to style a href links in React using Tailwind CSS ?
In this article, we will learn how we can style a href link in Reactjs. Since we use Tailwind CSS, Tailwind CSS describes itself as the first applicable CSS framework. Rather than focusing on the performance of a style object, Tailwind focuses on how it should be displayed. This makes it easier for the developer to explore new styles and transform
2 min read
Foundation CSS Base Typography Links
Foundation CSS is an open-source & responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails to look amazing & can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is b
3 min read
Primer CSS Links
Primer CSS is a free and open-source CSS framework. It is built upon the systems that create the foundation of the basic style elements such as spacing, typography, and colour. Created with GitHub’s design system, it is highly reusable and flexible. Primer CSS Links are used to decorate links in the webpage. Primer CSS has lots of customizations fo
3 min read
How to select all links within a Paragraph using CSS?
To style all links within a paragraph using CSS, you can use a simple selector. The following code selects all anchors (a) elements that are descendants of paragraph (p) elements. This rule allows you to apply specific styles, such as color and text decoration, exclusively to links within paragraphs, offering a targeted and efficient way to customi
1 min read
How to Remove Firefox's Dotted Outline on Buttons and links using CSS ?
In Firefox browser, dotted outline appears around the buttons, links as well as inputs. The ability to tell which piece is now in focus makes this outline useful for people who browse the web using a keyboard. This is a feature of Firefox's accessibility tools, which seek to make it simpler for users to navigate online pages using keyboard shortcut
3 min read
How to Style Links in CSS ?
Styling links in CSS is one of the fundamentals in web design that helps in creating an interactive and pleasant user experience through navigation. Links are core components for web pages, and using CSS, you can easily come up with the kind of look you want in terms of the overall appearance of the website or the brand. In this article, we will se
7 min read
How to Remove Underline from Links in CSS?
Ensuring that your links have the right appearance is important for usability. A common requirement is to remove the underline from links to give your webpage a cleaner look. You can do this using the CSS text-decoration: none; property. This article shows how to apply this style to all links or customize it further. Table of Content Using the text
2 min read
HTML DOM links Collection
The DOM links collection is used to return the collection of all <a> and <area> elements with the "href" attribute in the HTML document. The elements in the collection are sorted as they appear in the sourcecode. Syntax: document.links Properties: It contains a single property length which is used to return the number of <a> and
4 min read
How to disable HTML links using JavaScript / jQuery ?
Given an HTML link and the task is to disable the link by using JavaScript/jQuery. Approach 1: Disable HTML link using JavaScript using setAttribute() Method. JavaScript setAttribute() Method: This method adds the defined attribute to an element and gives it to the passed value. In case of the specified attribute already exists, the value is set/ch
5 min read
How to Create Navigation Links using HTML5 ?
In this article, we create a navigation link by using the <nav> tag in the document. The nav element represents a section of the page whose purpose is to provide navigational links, either in the current document or to other documents. The links in the "nav" element may point to other webpages or to different sections of the same webpage. It
1 min read
Express.js res.links() Function
The res.links() function is used to join the links provided as properties of the parameter to populate the response’s Link HTTP header field. Syntax: res.links( links ) Parameter: The link parameter describes the name of the link to be joined. Return Value: It returns an Object. Installation of the express module: You can visit the link to Install
2 min read
D3.js node.links() Function
The node.links() function returns an array of links to the children of the node object, each link object has a source and a target field that hold references to child nodes. Syntax: node.links(); Parameters: This method does not accept any parameters. Return Values: This method returns an array of links to the children of the node object. Example 1
1 min read
How to find all links with an hreflang attribute using jQuery ?
In this article, we will learn to find all links with a hreflang attribute. The hreflang is an attribute that tells search engines the relationship between pages in different languages on your website. To find all links with an hreflang attribute using jQuery, you can use the attribute selector $('[hreflang]'). This will select all elements that ha
2 min read
How to select all links inside the paragraph using jQuery ?
In this article, we will see how to write code to select all links inside the paragraph using jQuery. To select all links inside paragraph element, we use parent descendant selector. This selector is used to selects every element that are descendant to a specific (parent) element. Syntax: $("parent descendant") Approach: Here, we have created links
1 min read
How to customize links for pagination in Bootstrap ?
In many websites, we notice that when we search for something then all the related content is shown but if the number of content is large then it will make the website longer. To solve this, there is pagination in the webpage i.e, the contents are divided into many pages and on clicking the user can navigate through the related contents. Note: Pagi
4 min read
Bootstrap 5 Cards Titles, text, and links
Cards Titles, text, and links are used to add a title, text content, and links to a card. The .card-title class is used with <h*> tag to create the card title and the .card-subtitle class is used with <h*> tag to create the card subtitle. Similarly, the .card-link class is used with <a> tag to create a card link. Cards Titles, tex
2 min read
D3.js Shapes Links API Complete Reference
The D3 is an abbreviation of Data-Driven Documents, and D3.js is a resource JavaScript library for managing documents based on data. D3 is one of the most effective frameworks to work on data visualization. Shapes Links: D3.js linkVertical() FunctionD3.js linkHorizontal() FunctionD3.js link() FunctionD3.js link.source() FunctionD3.js link.target()
1 min read
Blaze UI Typography Hyper-links
Blaze UI is an open-source CSS-based UI library that provides a great structure for building websites quickly with a scalable and maintainable foundation. In this article, we will learn about Blazer UI Typography Hyper-links. Blazer UI Typography Hyper-links are used to provide some styling to hyperlinks i.e providing different colors to the links.
2 min read
Tachyons Element Links
Tachyon is a toolkit that is used to make a responsive website. In this article, we will learn about how to insert a clickable link using the Tachyons toolkit. Links are used to specifying the relationship between the current document and an external resource. Tachyons Element Links Classes: link underline blue hover-orange: This class is used to p
3 min read
React.js Blueprint Typography Links
BlueprintJS is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex data-dense for desktop applications. Typography is used to present content efficiently. Links are used to redirect users from one page to another. Typography Links has no special class to provide Blueprint styles.
2 min read
Bootstrap 5 Colored links
Bootstrap 5 Colored links are used to add colors to the link element. To set the colored links, we use the classes of utilities built on our theme colors. To make different color links, we will use .link-* class and add CSS styles to it. Colored links used Classes: link-primary: This class is used to set the primary color of the link element.link-s
2 min read
Explain the Typography and links in Bootstrap?
In this article, we will see the Typography & the Links In Bootstrap, along with understanding their basic implementation through the examples. Bootstrap Typography facilitates the different styling and formatting of text content, along with providing customization which includes customized headings, inline subheadings, lists, and paragraphs, a
2 min read
Which href value should we use for JavaScript links, "#" or "javascript:void(0)" ?
In this article, we will know which "href" should be used for JavaScript when we can use "#" or "javascript:void(0)". Let us understand it. Using the '#' value: The # is a fragment identifier used to refer to a specific section of the same document. When a user clicks a link with a # href, the browser will scroll to that section of the page specifi
3 min read
How to use CDN Links in React JS?
React is integrated in the projects using package managers like npm or yarn. However, there are some cases where using Content Delivery Network (CDN) links can be a advantage, especially for quick prototypes, or when integrating React into existing projects. The two libraries imported CDN Links are discussed below Table of Content Importing Bootstr
3 min read
Open all persons solution links from submission page using JavaScript
JavaScript is a high-level, interpreted programming language that conforms to the ECMAScript specification. jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation. Example: Step 1: Open any geeksforgeeks solution page. Open the page in inspect mode by pressing F12 or through inspect option.step 2: Now copy and
2 min read