Skip to main content
CSS-Tricks
Since 2007
  • Articles
  • Guides
  • Almanac
  • Links
  • Picks
  • Newsletter
  • Search

Articles Tagged
:focus-within

8 Articles
Direct link to the article How We Improved the Accessibility of Our Single Page App Menu
:focus-within accessibility focus menu navigation

How We Improved the Accessibility of Our Single Page App Menu

I recently started working on a Progressive Web App (PWA) for a client with my team. We’re using React with client-side routing via React Router, and one of the first elements that we made was the main menu. Menus …

Luke Denton on Feb 25, 2021
Direct link to the article Fixing Smooth Scrolling with Find-on-Page
:focus-within smooth scrolling

Fixing Smooth Scrolling with Find-on-Page

Back when we released the v17 design (we’re on v18 now) of this site. I added html { scroll-behavior: smooth; } to the CSS. Right away, I got comments like this (just one example):

… when you control+f or

…
Chris Coyier on Jan 12, 2021
Direct link to the article How to Create a “Skip to Content” Link
:focus-within accessibility links skip link

How to Create a “Skip to Content” Link

Skip links are little internal navigation links that help users move around a page. It’s possible you’ve never actually seen one before because they’re often hidden from view and used as an accessibility enhancement that lets keyboard users and screen …

Paul Ryan on Mar 17, 2020
Direct link to the article Don’t comma-separate :focus-within if you need deep browser support
:focus-within

Don’t comma-separate :focus-within if you need deep browser support

I really like :focus-within. It’s a super useful selector that allows you to essentially select a parent element when any of its children are in focus.

Say you wanted to reveal some extra stuff when a <div></div> is hovered… …

Chris Coyier on Jul 24, 2019
Direct link to the article A CSS Approach to Trap Focus Inside of an Element
:focus-within accessibility dialog

A CSS Approach to Trap Focus Inside of an Element

I recently read this article by Keith Grant which introduced the newly arrived <dialog. Excited by this new UI element, I immediately sat down to experiment with it to see how it can be used effectively as a modal …

Kushagra Gour on Mar 27, 2018
Direct link to the article Keeping Parent Visible While Child in :focus
:focus-within accessibility focus

Keeping Parent Visible While Child in :focus

Say we have a <div></div>.

We only want this div to be visible when it’s hovered, so:

div:hover { 
  opacity: 1; 
}

We need focus styles as well, for accessibility, so:

div:hover,
div:focus { 
  opacity: 1; 
}

But div’s …

Chris Coyier on Dec 12, 2017
Direct link to the article :focus-within
:focus-within forms

:focus-within

The :focus-within pseudo-selector in CSS is a bit unusual, although well-named and rather intuitive. It selects an element if that element contains any children that have :focus.

form:focus-within {
  background: lightyellow;
}

Which works like this…

<!-- this form 
…
Chris Coyier on Jul 29, 2017
Direct link to the article The `:focus-within` Pseudo Class
:focus-within parent selectors

The `:focus-within` Pseudo Class

Nice find by Ian Devlin:

The :focus-within pseudo class becomes active when an element itself has focus or if any of its descendants does.

Selecting a parent element based on children is lonnng awaited. The crown jewel of that …

Chris Coyier on May 12, 2017

CSS-Tricks is powered by DigitalOcean.

Get Curated Front-End Roundups Right in Your Inbox

Coming back really, really soon! See past issues →

CSS-Tricks
  • About the site
  • Contact us
  • Write for CSS-Tricks!
  • Advertising
  • RSS Feeds
Social
  • Bluesky
  • Mastodon
  • CodePen
  • X / Twitter
  • LinkedIn
Legalese
  • CSS-Tricks License
  • AI Statement
Back to Top