CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

:Visited


The :visited pseudo-class applies styles to an <a> element that links to a URL the user has already visited. For privacy reasons, the properties that can be changed with this pseudo-class are limited.

Example 1: Basic Visited Link

/* Style for a link */
.my-link {
  color: #007bff;
}

/* Change the color of the link if it has been visited */
.my-link:visited {
  color: #6c757d;
}

Explanation

This is the most common use case for :visited. It changes the color of a link after the user has navigated to it, providing a helpful visual cue of their Browse history on the site.


Example 2: Visited Link with Background Color

/* Style for a link */
.my-link {
  color: #007bff;
}

/* Change the background color of a visited link */
.my-link:visited {
  background-color: #f8f9fa;
}

Explanation

You can also change the background-color of a visited link. This can be used to subtly highlight links that have already been explored by the user.


Example 3: Styling the Outline of a Visited Link

/* Style for a link */
.my-link {
  outline: 1px solid #007bff;
}

/* Change the outline color of a visited link */
.my-link:visited {
  outline-color: #6c757d;
}

Explanation

The outline-color is another property that can be safely modified for visited links, offering another way to visually distinguish them.


Example 4: Using border-color on Visited Links

/* Style for a link with a border */
.my-link {
  border-bottom: 2px solid #007bff;
  padding-bottom: 2px;
}

/* Change the border color of a visited link */
.my-link:visited {
  border-bottom-color: #6c757d;
}

Explanation

If your link design includes borders, you can change their color for visited links. This allows for more integrated visual feedback within your site's design.


Example 5: Combining with Other Pseudo-classes

/* Default link style */
a {
  color: #007bff;
}

/* Visited link style */
a:visited {
  color: #6c757d;
}

/* Hover style for unvisited links */
a:hover {
  color: #0056b3;
}

/* Hover style for visited links */
a:visited:hover {
  color: #5a6268;
}

Explanation

This example shows how to provide different hover colors for visited and unvisited links, creating a more nuanced and user-friendly navigation experience.