{"id":334702,"date":"2021-02-23T09:58:07","date_gmt":"2021-02-23T17:58:07","guid":{"rendered":"https:\/\/css-tricks.com\/?page_id=334702"},"modified":"2021-08-27T10:09:24","modified_gmt":"2021-08-27T17:09:24","slug":"current","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/selectors\/c\/current\/","title":{"rendered":":current"},"content":{"rendered":"\n

:current<\/code> is a CSS pseudo-selector that matches an element or an ancestor of an element that’s currently in display. So, we can match items that have rendered on the screen like this:<\/p>\n\n\n\n

:current(p, ul);<\/code><\/pre>\n\n\n\n

…and that will select all currently displayed paragraphs and unordered lists. It’s a lot like is()<\/a><\/code> in that sense. But what makes this pseudo-selector super cool is that it’s part of what the CSS Selectors Level 4 specification calls “time dimensional” pseudo-classes<\/a> which are designed to match elements along a timeline, such as subtitles in a video.<\/p>\n\n\n\n\n\n\n

Meet WebVTT<\/h3>\n\n\n

That’s what’s used to render subtitles in a video. And it does that by defining a timeline that pairs subtitles with time ranges so they align with the speech that’s playing.<\/p>\n\n\n\n

WEBVTT\n\n00:00:00.000 --> 00:00:03.000\n- [Birds chirping]\n- It's a beautiful day!\n\n00:00:04.000 --> 00:00:07.000\n- [Creek trickling]\n- It is indeed!\n\n00:00:08.000 --> 00:00:10.000\n- Hello there!<\/code><\/pre>\n\n\n\n

As the video plays, WebVTT is running alongside it, displaying the subtitles that are defined within the time ranges. That means there’s a time dimension where we have past, current, and future states for the subtitles. After a subtitle finishes playing, it becomes part of the past. Upcoming subtitles? Yep, they’re in the future.<\/p>\n\n\n\n