Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14
Chapter 3

Links, Pseudo-classes & Responsive Design

Interactive states and media/container queries for responsive layouts.


Link & Interaction Pseudo-class Selectors

Pseudo-classMatches
a:linkUnvisited link — default state
a:visitedLink the user has already clicked
a:hoverMouse is over the link
a:activeLink is being clicked right now
button:focus-visible2025: keyboard focus only (not mouse click)
input:invalidForm field fails validation
:user-invalid2025: shows only after user interaction
a { font-weight: bold; }
a:link    { color: #0084D8; }
a:visited { color: #90E0EF; }
a:hover   { color: #FF8703; text-decoration: none; }
a:active  { color: #FB8500; }

button:focus-visible { outline: 3px solid #0084D8; }

Responsive Design & Media Queries (2025)

Media queries apply styles only under specific conditions.

  • @media (min-width: 768px) — mobile-first approach.
  • Common breakpoints: 640px, 768px, 1024px, 1280px.
  • Also query prefers-color-scheme and prefers-reduced-motion.
/* Mobile-first default */
.grid { display: block; }

/* Tablet+ */
@media (min-width: 768px) {
  .grid { display: grid; grid-template-columns: 1fr 1fr; }
}

/* Desktop */
@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}

/* Accessibility — reduce motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}

Container Queries (2025)

Container queries respond to the parent container's width rather than the viewport — components become truly reusable.

.card-wrapper { container-type: inline-size; }

@container (min-width: 400px) {
  .card { display: flex; flex-direction: row; }
}

Activity — complete the code

Complete the code correctly to mark this lesson as complete automatically.

Complete the pseudo-class and the media queries.

a: { color: red; }
 
@media (min-width: ) {
.grid { display: grid; }
}
 
@media (prefers-reduced-motion: ) {
* { animation: none; }
}