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

:Link


The :link pseudo-class specifically targets <a> elements that have an href attribute and have not yet been visited. It is often used to set the default state for links.

Example 1: Basic Unvisited Link

/* Style for a link that has not been visited */
.my-link:link {
  color: #007bff;
  text-decoration: none;
}

Explanation

This code sets the color of all unvisited links to blue and removes the default underline, providing a clean, initial appearance for navigation.


Example 2: Combining :link and :visited

/* Style for unvisited links */
a:link {
  color: #dc3545;
}

/* Style for visited links */
a:visited {
  color: #6c757d;
}

Explanation

This is a classic example of setting up the two primary states of a link: one color for links the user has not yet clicked, and another for those they have.


Example 3: Styling an Unvisited Button-like Link

/* Style for a link styled as a button */
.button-link:link {
  background-color: #28a745;
  color: white;
  padding: 10px 15px;
  border-radius: 5px;
}

Explanation

The :link pseudo-class can be used to style links that are designed to look like buttons, ensuring that only unvisited links get the primary "call to action" styling.


Example 4: Using :link with a Specific Class

/* Style for primary navigation links that are unvisited */
.nav-primary:link {
  font-weight: bold;
}

Explanation

This example demonstrates how to apply a specific style (bold text) only to unvisited links that also have a particular class, allowing for more targeted styling.


Example 5: The LVHA Order

/* 1. :link */
a:link {
  color: #007bff;
}

/* 2. :visited */
a:visited {
  color: #6c757d;
}

/* 3. :hover */
a:hover {
  color: #0056b3;
}

/* 4. :active */
a:active {
  color: #dc3545;
}

Explanation

This shows the recommended order for defining link-related pseudo-classes: :link, :visited, :hover, :active (LVHA). This order ensures that the styles are applied correctly due to CSS specificity rules.