CSS Links & Media
Style links, states, and responsive media; pair with media queries for adaptive layouts.
Introduction to CSS Links & Media
Theory: Links should be visually clear in every state (default, hover, focus, visited). Consistent link styling improves navigation confidence.
What You'll Learn:
Learn how to style links, embedded media, icons, and interactive states using clean CSS patterns.
Links and media are key interaction points in UI. Good CSS styling improves clarity, accessibility, and engagement.
Styling Link States
Theory: This topic explains practical CSS concepts used in real interfaces. Understanding the theory helps you choose the right properties and patterns.
Use pseudo-classes to style links consistently across states: default, visited, hover, focus, and active.
Simple Link State Example:
a {
color: #2563eb;
text-decoration: none;
}
a:visited { color: #7c3aed; }
a:hover,
a:focus { text-decoration: underline; }
a:active { color: #1d4ed8; }
Responsive Media Styling
Theory: Responsive media styling keeps embedded content stable across devices. Aspect ratio and overflow handling prevent layout shifts.
| Element | Common CSS | Purpose |
|---|---|---|
img | max-width:100%; height:auto; | Prevents overflow on small screens |
video | width:100%; border-radius:12px; | Responsive media with modern UI |
iframe | aspect-ratio:16/9; width:100%; | Responsive embeds (YouTube/maps) |
figure | margin:0; | Cleaner image + caption alignment |
Icon and Social Link Styling
Theory: This topic explains practical CSS concepts used in real interfaces. Understanding the theory helps you choose the right properties and patterns.
Icon Circle Example:
.social-link {
width: 40px;
height: 40px;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: #e2e8f0;
color: #0f172a;
}
.social-link:hover {
background: #0d6efd;
color: #fff;
}
CSS Links & Media Best Practices
Theory: Links should be visually clear in every state (default, hover, focus, visited). Consistent link styling improves navigation confidence.
- Always provide visible
:focusstyles for keyboard users. - Maintain sufficient color contrast for links and icons.
- Use
max-width: 100%for responsive media. - Keep hover effects subtle and consistent.
- Use descriptive link text instead of generic “Click here”.
Extended Tutorial: Links & Media Queries
Theory: Links have states: :link, :visited, :hover, :active, :focus-visible. Style visited state carefully—avoid relying on color alone for critical info.
Example: Accessible link styles
a {
color: #1d4ed8;
text-decoration-thickness: 2px;
text-underline-offset: 3px;
}
a:visited { color: #6d28d9; }
a:hover { color: #1e3a8a; }
a:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 2px;
}
Responsive images & print
Use max-width: 100%; height: auto; on images. For print stylesheets, hide navigation and expand link URLs if needed.
Example: Fluid image
img, video { max-width: 100%; height: auto; }
@media print {
a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.85em; }
}