EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

CSS Link Color

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » CSS Tutorial » CSS Link Color

CSS Link Color

Introduction to CSS Link Color

The advantage of using Cascading Style Sheet is that it offers every kind of styling. The user can customize how each element is styled, for maximum ease of use for the end user. Customizing the behaviour of a hyperlink is also offered in CSS. The developer can control how the link will behave using various pseudo classes. Also, one can assign different colors, and the link color will change according to its usage. This styling helps the end user segregate between various links,like, one which has not been clicked upon yet or the one which has already been clicked on. Let us have a look at some of the properties offered by CSS to customize and animate the hyperlinks on a page.

Usage and Examples of CSS Link Color

There are various states of a hyperlink. CSS offerspseudo classes for each of these states, which can be custom styles by developers according to the requirement of the web page. The above mentioned states of a hyperlink are: link, visited, hover, active.The state ‘link’ refers to an untouched link, yet to be accessed. ‘Visited’ refers to a link, which has been accessed. ‘Hover’ is the state of the link, when the user will hover over the link. And finally ‘active’ refers to the state of the link when it is immediately clicked upon. Let us look at the example and see how each state can be styled for, and see its demonstration.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

1. Demonstrating different colors for different link states, using External CSS

  • Since we are using external CSS, we will start by creating the CSS file first.
  • As stated above, we will be styling the hyperlink element and each state can be styled as a pseudo class. In other terms, we will style <a> element and each state will be defined as a class i.e. a:link, a:hover, a:visited, a:active.
  • We will define the pseudo class, and define the styling for each. The coding for each class will look like this:

a:link{
font-style: normal;
color: blue;
font-family: Arial, Helvetica, sans-serif;
}

  • The final CSS code will look as below:

a:link{
font-style: normal;
color: blue;
font-family: Arial, Helvetica, sans-serif;
}
a:hover{
font-style: italic;
color: darkgreen;
}
a:visited{
font-style: normal;
color: darkred;
font-family: Arial, Helvetica, sans-serif;
}
a:active{
font-style: italic;
color: yellow;
}

  • Next, we will code for the HTML page. Since this is example uses external CSS, in the header section, we will call for the external CSS file.
  • In the body section we will define the link, using the element <a>. The final HTML code will look as follows:

<html>
<head>
<title>Hyperlink Styling</title>
<link rel="stylesheet" type="text/css" href="link.css">
</head>
<body>
<h2>This page demonstrates the various states of hyperlink</h2>
<b><a href="https://www.google.com">This is a hyperlink</a></b>
<ol>
<li>If the link is not used, it will appear Blue and normal</li>
<li>If the link is hovered upon, it will appear Green and Italic </li>
<li>If the link has been used, it will appear Red and normal</li>
<li>If the link is active, it will be Yellow and Italic</li>
</ol>
</body>
</html>

Popular Course in this category
CSS Training (9 Courses, 9+ Projects)9 Online Courses | 9 Hands-on Projects | 61+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,416 ratings)
Course Price

View Course

Related Courses
Bootstrap Training (2 Courses, 6+ Projects)jQuery Training (8 Courses, 5 Projects)
  • We can see the final outcome by saving this page and opening it through a browser.
  • The link will initially appear to be blue, as in the first screenshot.

CSS Link Color-1.1

  • It will change color to Green and italic when we will hover upon it.

CSS Link Color-1.2

  • You can observe the color change to yellow, the exact moment the link is clicked.

CSS Link Color-1.3

  • And in the final screenshot, you can see that the link, once visited, turns into a dark red color.

CSS Link Color-1.4

2. Styling hyperlink using Internal CSS

  • In this example, we will demonstrate the styling for hyperlink, using internal CSS.
  • Since this example uses internal CSS, we will directly code for the HTML page.
  • In the header section, we will define the styling for each state of the link (as a pseudo class), within the <style> element. The head section will be coded as below:

<head>
<title>Hyperlink Styling</title>
<style>
a:link{
font-style: normal;
color: blue;
font-family: Arial, Helvetica, sans-serif;
}
a:hover{
font-style: italic;
color: darkgreen;
}
a:visited{
font-style: normal;
color: darkred;
font-family: Arial, Helvetica, sans-serif;
}
a:active{
font-style: italic;
color: yellow;
}
</style>
</head>

  • Now, in the body section, similar to the above example, we will make use of the element <a> to demonstrate the usage of each state of the link that has been styled. The final HTML code will should look as below:

<html>
<head>
<title>Hyperlink Styling</title>
<style>
a:link{
font-style: normal;
color: blue;
font-family: Arial, Helvetica, sans-serif;
}
a:hover{
font-style: italic;
color: darkgreen;
}
a:visited{
font-style: normal;
color: darkred;
font-family: Arial, Helvetica, sans-serif;
}
a:active{
font-style: italic;
color: yellow;
}
</style>
</head>
<body>
<h2>This page demonstrates the various states of hyperlink</h2>
<b><a href="https://www.google.com">This is a hyperlink</a></b>
<ol>
<li>If the link is not used, it will appear Blue and normal</li>
<li>If the link is hovered upon, it will appear Green and Italic </li>
<li>If the link has been used, it will appear Red and normal</li>
<li>If the link is active, it will be Yellow and Italic</li>
</ol>
</body>
</html>

  • Saving this page and opening it through a browser will help us in seeing the outcome similar to the below screenshots.
  • The link will initially appear to be blue, as in the first screenshot.

CSS Link Color-1.5

  • It will change color to Green and italic when we will hover upon it.

Output-1.6

  • You can observe the color change to yellow, the exact moment the link is clicked.

Output-1.7

  • And in the final screenshot, you can see that the link, once visited, turns into a dark red color.

Output-1.8

Conclusion

Hence the above examples helped us in seeing how different colors and states can be used in styling the links, which can make it easier for the end users to use the links on a page. The developers can use these states of the link as required by the page. Also, this is just one of the few options on how links can be stylized.

Recommended Articles

This is a guide to CSS Link Color. Here we also discuss the introduction and usage of css link color along with a different example and its code implementation. You may also have a look at the following articles to learn more –

  1. CSS Parent Selector
  2. CSS in React
  3. CSS Combinators
  4. CSS Text Color

CSS Training (9 Courses, 9+ Projects)

9 Online Courses

9 Hands-on Projects

61+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
CSS Tutorial
  • CSS
    • Introduction To CSS
    • What is CSS?
    • Uses Of CSS
    • Advantages of CSS
    • Career In CSS
    • CSS Commands
    • Is Css Case Sensitive
    • CSS object-fit
    • Types of CSS Selectors
    • CSS Radio Button
    • CSS Attribute Selector
    • CSS first child of class
    • CSS Selector nth Child
    • CSS Parent Selector
    • CSS Child Selector
    • CSS Not Selector
    • CSS Descendant Selector
    • CSS Inline Style
    • Checkbox CSS
    • CSS Appearance
    • CSS Font Properties
    • CSS font-variant
    • CSS Pagination
    • CSS Table Styling
    • CSS Table Cell Padding
    • CSS Padding Color
    • CSS Text Formatting
    • CSS for Text-Shadow
    • CSS text-stroke
    • CSS text-indent
    • CSS Rotate Text
    • CSS Text Color
    • CSS Center Div
    • CSS Arrow
    • CSS Arrow Down
    • CSS offset
    • CSS Cursor
    • CSS Layout
    • CSS Grid Layout
    • Button in CSS
    • CSS Button Border
    • text-align in CSS
    • CSS Horizontal Align
    • CSS Position
    • CSS Box Sizing
    • CSS box-shadow
    • CSS Text Underline
    • CSS Text Outline
    • CSS Blinking Text
    • Text Decoration CSS
    • CSS Vertical Align
    • CSS Word Wrap
    • CSS Padding
    • CSS Font Color
    • CSS Color Generator
    • CSS Margin Right
    • CSS Margin Color
    • CSS Color Codes
    • CSS Color Transparent
    • CSS Color Chart
    • CSS Link Color
    • CSS z-index
    • CSS Curved Border
    • CSS Border Left
    • CSS left
    • CSS Gradient Generator
    • Radial Gradient in CSS
    • CSS Shape Generator
    • CSS Triangle Generator
    • CSS background-color
    • CSS Background Image
    • CSS background-clip
    • CSS background-blend-mode
    • CSS Drop Shadow
    • CSS line height
    • CSS line break
    • Sticky Footer CSS
    • CSS Header Design
    • CSS Border Style
    • CSS Border Generator
    • Sticky Sidebar CSS
    • CSS Transparent Border
    • CSS Border Radius
    • CSS translate
    • CSS transform
    • CSS 3D Transforms
    • CSS Text Transform
    • CSS Transition Effects
    • CSS Transition Property
    • CSS Animation Transition
    • Negative Margin CSS
    • CSS Navigation Bar
    • CSS Overflow
    • CSS overflow-wrap
    • CSS Lists
    • CSS list-style
    • CSS Order
    • CSS Box Model
    • CSS Inner Border
    • CSS Icon
    • Menu Icon CSS
    • CSS Multiple Borders
    • Opacity in CSS
    • CSS Float Right
    • CSS Clear Float
    • CSS clip
    • CSS disabled
    • CSS Border Padding
    • Border Images in CSS
    • CSS Visibility
    • CSS Validator
    • CSS Clearfix
    • CSS Counter
    • CSS Letter Spacing
    • CSS root
    • CSS zoom
    • CSS calc()
    • CSS.supports()
    • CSS Loader
    • Media Query CSS
    • CSS @keyframes
    • CSS @bottom
    • CSS page-break-after Property
    • CSS page-break
    • CSS Position Fixed
    • CSS skew()
    • CSS Row
    • CSS Masking
    • CSS Scrollbar
    • CSS Overlay
    • CSS Important
    • CSS Cursor Hand
    • CSS Inherit
    • CSS Position Relative
    • CSS Compressor
    • CSS tricks
    • CSS Outline Property
    • CSS Flexbox Properties
    • CSS flex-direction
    • CSS content property
    • CSS Typography
    • CSS Formatter
    • CSS nowrap
    • CSS Column
    • GridView CSS
    • CSS Viewport
    • CSS Minify
    • CSS Combinators
    • CSS in React
    • CSS Matrix 
    • CSS Pseudo Elements
    • CSS Pseudo Classes
    • CSS Pointer Events
    • CSS Resize
    • CSS Inheritance
    • CSS Interview Questions
    • Cheat Sheet CSS
  • CSS3
    • What is CSS3?
    • CSS3 Interview Questions
    • Cheat sheet CSS3
  • sass
    • How to Install SASS
    • SASS Interview Questions
    • What is Sass
    • SASS Comments
    • Sass Variables
    • SASS Import
    • SASS if else
    • SASS Nesting
    • SASS @each
    • SASS @at-root
    • SASS @extend
    • SASS @media
    • SASS @for
    • SASS Map
    • SASS Selectors
    • SASS Color Functions
    • SASS Mixins

Related Courses

CSS Training Course

Bootstrap Training Course

JQuery Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - CSS Training (9 Courses, 9+ Projects) Learn More