Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Welcome to Chapter 8! 🔗
Hyperlinks (<a> tags) are the backbone of the World Wide Web. They allow users to jump from page to page, download documents, and trigger interactive experiences.
By default, every web browser renders links in a vintage 1990s style:
While this default styling made the early internet functional, modern websites style links to match brand colors, provide delightful hover feedback, and even transform links into stylish call-to-action buttons.
In this lesson, you will master:
:link, :visited, :hover, :active, :focus)To understand link states, imagine your School Bus Pass Card:
+-------------------------------------------------------------------------+ | THE LIFE CYCLE OF A HYPERLINK | +-------------------------------------------------------------------------+ | 1. :link --> BRAND NEW BUS PASS | | You just got it at the start of the academic year. | | Never scanned at the bus gate yet (unvisited). | | | | 2. :visited --> STAMPED BUS PASS | | The conductor has already stamped it. You have ridden | | this route before (visited page). | | | | 3. :hover --> BRINGING PASS CLOSE TO SENSOR | | Your hand moves the pass near the RFID reader. It | | glows green anticipating a scan (mouse over link). | | | | 4. :active --> PRESSING THE TOUCHPAD BUTTON | | The split second your finger presses down firmly on | | the machine surface (mouse click held down). | | | | 5. :focus --> HIGHLIGHTED BY FLASHLIGHT | | A student using a keyboard hits the "Tab" key. A blue | | outline marks the pass for accessibility. | +-------------------------------------------------------------------------+
A pseudo-class is a special keyword added to a CSS selector preceded by a colon (:). It specifies a special state of the selected element.
Syntax:
For example, a:hover targets <a> elements only while the user hovers their mouse pointer over them!
Let's examine the 5 states you can style for hyperlinks:
a:link (Unvisited)Matches any link the user has not yet clicked in their current browser session or history.
a:visited (Visited)Matches links the user has already visited.
:visited: For user security and privacy, modern browsers only permit changing color, background-color, and border colors on :visited. You cannot change font-size, padding, or display to prevent malicious scripts from detecting browsing history.a:hover (Mouse Over)Triggers when the user's mouse cursor hovers over the link. This provides visual feedback showing that the text is clickable.
a:active (Clicking Down)Triggers during the exact millisecond between pressing the mouse button down and releasing it.
a:focus (Keyboard Navigation)Triggers when a keyboard user navigates the page by pressing the Tab key. This is critical for users with motor disabilities who cannot use a mouse.
In CSS, order matters because of the cascade! If you write link pseudo-classes in the wrong order, earlier rules can accidentally override later rules.
To remember the correct order, use the memory trick LoVe HAte:
If you put a:hover before a:visited:
google.com. The browser marks the link as :visited.:visited and :hover apply.:visited was declared lower in the CSS file, its color wins, and the hover color will never appear!Always write them in the order: Link, Visited, Hover, Active!
Most modern websites prefer a clean look where links do not have constant underlines, but show an underline or color shift only on hover:
In web design, primary call-to-action (CTA) buttons (like "Enroll in Class" or "Download Admit Card") are frequently coded as HTML <a> tags styled to look like buttons.
Because <a> is an inline element by default, top and bottom padding do not push other elements away properly. To fix this, always set display: inline-block:
+-------------------------------------------------------------+ | TRANSFORMING <a> INTO A BUTTON | +-------------------------------------------------------------+ | <a> Enroll Now </a> | | | | + display: inline-block (allows width, height, padding) | | + background-color (brand blue or green) | | + color: white (clean contrast text) | | + padding: 12px 24px (roomy touch target) | | + border-radius: 6px (rounded smooth edges) | | + text-decoration: none (removes vintage underline) | | + box-shadow (elevated 3D feel) | +-------------------------------------------------------------+
| Bad Practice ❌ | Why It Fails ⚠️ | Better Approach ✅ |
|---|---|---|
Writing :hover before :visited | Visited links won't show the hover color due to cascade order. | Always follow the LVHA rule: :link, :visited, :hover, :active. |
Adding padding to <a> without display: inline-block | Default inline links do not respect vertical padding or margins cleanly. | Add display: inline-block; so padding and spacing behave reliably. |
Removing :focus outline with outline: none | Keyboard users cannot see which link is currently selected! | Keep or customize the focus ring: outline: 3px solid #3b82f6; outline-offset: 2px;. |
Trying to change font-size on :visited | Modern browsers block non-color property changes on visited links for security. | Only alter color and background-color on :visited. |
<a>) represent navigational pathways across the web.:link (unvisited), :visited (already clicked), :hover (mouse over), :active (mouse pressed down), and :focus (keyboard tabbed).text-decoration: none; removes the default browser underline.display: inline-block;, padding, background-color, and border-radius to convert any link into a gorgeous button.a:hover before a:visited in your stylesheet?display: inline-block when styling an <a> tag as a button with padding?a:visited to colors only?school-portal-links.html.In the next lesson, we will continue your web styling journey with Styling Ordered and Unordered Lists (Links, Lists and Tables Styling).
👉 Continue to Next Lesson: Styling Ordered and Unordered Lists →
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Box Shadows and Text Shadows: Depth and Elevation | Styling Ordered and Unordered Lists |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.