How to create an expanding search bar using :focus-within

Kevin Powell on YouTubeWatch on YouTube

SaveMark complete

Sign in to save videos and track what you’ve finished.

IntermediateUI33 min

About this video

Shows how to build an expanding search bar without JavaScript, using the CSS :focus-within selector. The walkthrough uses SCSS, with a CodePen to view the compiled CSS for anyone unfamiliar with it.

What you’ll learn

  • Build an expanding search bar using only CSS
  • Apply :focus-within to style a container based on its child's focus
  • Structure SCSS styles to follow along with the compiled CSS