<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abhijit on Medium]]></title>
        <description><![CDATA[Stories by Abhijit on Medium]]></description>
        <link>https://medium.com/@abhijitkhatua?source=rss-51156271a57c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NRC7-wHuEMi64hHebdWu7Q.jpeg</url>
            <title>Stories by Abhijit on Medium</title>
            <link>https://medium.com/@abhijitkhatua?source=rss-51156271a57c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 05:20:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhijitkhatua/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Popover API is here and your JavaScript owes you an apology]]></title>
            <link>https://medium.com/@abhijitkhatua/the-popover-api-is-here-and-your-javascript-owes-you-an-apology-f44ba7e7aeff?source=rss-51156271a57c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f44ba7e7aeff</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[popoverapi]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Abhijit]]></dc:creator>
            <pubDate>Thu, 26 Feb 2026 16:34:50 GMT</pubDate>
            <atom:updated>2026-02-26T16:34:50.029Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Popover API" src="https://cdn-images-1.medium.com/max/1024/1*LYBzKFX-WOmitJ7eh_3odA.png" /></figure><p>The web is evolving and this time it’s actually removing code from your codebase instead of adding to it — which should get you excited enough to keep reading.</p><p>If you’ve built a tooltip, dropdown, or floating UI from scratch you know the pain — toggle a class, manage state, handle outside clicks, trap focus, fight z-index, write 12 event listeners, cry. The Popover API handles all of that natively, with browser-level accessibility baked in.</p><h3>Browser support</h3><p>Baseline 2024 — Chrome 114, Edge 114, Firefox 125, Safari 17. Ship it.</p><h3>What you actually get for free</h3><p>Before writing a single line, here’s what the browser handles for you out of the box:</p><ul><li><strong>Top layer promotion</strong> — popovers float above everything, no z-index management needed</li><li><strong>Light-dismiss</strong> — clicking outside closes it and returns focus automatically</li><li><strong>Focus management</strong> — opening a popover moves tab focus inside it</li><li><strong>Keyboard bindings</strong> — Esc closes it and returns focus</li><li><strong>Semantic bindings</strong> — the trigger and target are connected meaningfully for assistive tech</li></ul><p>That’s a lot of stuff you’re not writing.</p><h3>The basics</h3><p>Minimum setup, zero JS:</p><pre>&lt;button popovertarget=&quot;my-popover&quot;&gt;Open&lt;/button&gt;</pre><pre>&lt;div id=&quot;my-popover&quot; popover&gt;<br>  &lt;p&gt;I am a popover. Hit &lt;kbd&gt;Esc&lt;/kbd&gt; or click away to close me.&lt;/p&gt;<br>&lt;/div&gt;</pre><p>popover on the element marks it as a popover (hidden by default, lives in the top layer). popovertarget on the button wires up the trigger — its value must match the popover&#39;s id. The browser handles the rest.</p><h3>auto vs manual</h3><p><strong>popover=&quot;auto&quot;</strong> (default when you just write popover) — light-dismiss on outside click or Esc, and only one auto popover stays open at a time. Opening a new one closes the previous one automatically.</p><p><strong>popover=&quot;manual&quot;</strong> — doesn&#39;t close on outside click or Esc, doesn&#39;t close other popovers. You need to handle closing explicitly, either with a close button or JS. Great for persistent toasts, notifications, or multi-step flows where you want full control:</p><pre>&lt;button popovertarget=&quot;toast&quot; class=&quot;trigger&quot;&gt;Show notification&lt;/button&gt;</pre><pre>&lt;div id=&quot;toast&quot; popover=&quot;manual&quot;&gt;<br>  Deploy successful 🎉<br>  &lt;button popovertarget=&quot;toast&quot; popovertargetaction=&quot;hide&quot;&gt;<br>    &lt;span aria-hidden=&quot;true&quot;&gt;❌&lt;/span&gt;<br>    &lt;span class=&quot;sr-only&quot;&gt;Close&lt;/span&gt;<br>  &lt;/button&gt;<br>&lt;/div&gt;</pre><p>Notice popovertargetaction=&quot;hide&quot; — this is how you wire up a dedicated close button declaratively without JS. There&#39;s also popovertargetaction=&quot;show&quot; if you need separate open and close triggers instead of a single toggle.</p><p><strong>Bonus:</strong> There’s a third type popover=&quot;hint&quot; being discussed in standards bodies — it would open without closing other popovers, useful for tooltips. Not implemented yet but worth keeping an eye on.</p><h3>JS API</h3><p>Three methods:</p><pre>const el = document.getElementById(&#39;my-popover&#39;);</pre><pre>el.showPopover();<br>el.hidePopover();<br>el.togglePopover();</pre><p>And for reacting to state changes:</p><pre>el.addEventListener(&#39;beforetoggle&#39;, (e) =&gt; {<br>  console.log(&#39;from:&#39;, e.oldState); // &quot;closed&quot; or &quot;open&quot;<br>  console.log(&#39;to:&#39;, e.newState);<br>});</pre><pre>el.addEventListener(&#39;toggle&#39;, (e) =&gt; {<br>  console.log(&#39;now:&#39;, e.newState);<br>});</pre><p>beforetoggle fires before the transition — useful if you need to cancel something or fetch data before opening. toggle fires after.</p><h3>Styling</h3><p>Target it with [popover] or its ID, use :popover-open for the open state:</p><pre>[popover] {<br>  border: none;<br>  border-radius: 10px;<br>  padding: 1rem;<br>  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);<br>}</pre><p>For animations, you need @starting-style — this defines the element&#39;s state <em>before</em> it enters the top layer, giving the browser a &quot;from&quot; state to transition from. Without it, entry animations simply won&#39;t fire:</p><pre>[popover] {<br>  transition: opacity 0.2s, transform 0.2s, display 0.2s allow-discrete;<br>  opacity: 1;<br>  transform: translateY(0);<br>}</pre><pre>@starting-style {<br>  [popover]:popover-open {<br>    opacity: 0;<br>    transform: translateY(-8px);<br>  }<br>}</pre><p>And since popovers live in the top layer, ::backdrop comes for free:</p><pre>[popover]::backdrop {<br>  background: rgba(0, 0, 0, 0.4);<br>  backdrop-filter: blur(2px);<br>}</pre><h3>Popover vs &lt;dialog&gt; — know the difference</h3><p>People mix these up so let’s settle it once and for all:</p><p>popover opens declaratively via popovertarget or JS, supports light-dismiss, uses :popover-open for styling, and doesn&#39;t block page interaction. &lt;dialog&gt; opens with dialog.showModal(), closes with dialog.close(), makes the rest of the page inert, and semantically represents a blocking interactive component — none of which popover does.</p><p>The key thing: <strong>popover is non-modal</strong> — it doesn’t make the rest of the page inert. If you need to block interaction and force the user to respond, reach for &lt;dialog&gt;. If you just need a floating layer that plays nicely with the rest of the page, popover is your friend.</p><p>Side note — because dialog shipped before popover, it doesn&#39;t have declarative trigger support yet. A new invoketarget property is being prototyped to fix that, bringing the same declarative wiring popover already has.</p><h3>Nested popovers</h3><p>Auto popovers normally close each other, but there’s one exception — if a popover is triggered <em>from inside</em> an already open popover, both stay open. This is how nested menus work natively with zero JS coordination:</p><pre>&lt;div id=&quot;menu&quot; popover&gt;<br>  &lt;button popovertarget=&quot;submenu&quot;&gt;More options →&lt;/button&gt;<br>&lt;/div&gt;</pre><pre>&lt;div id=&quot;submenu&quot; popover&gt;<br>  Nested stuff here<br>&lt;/div&gt;</pre><p>The browser tracks the popover stack and handles it correctly.</p><h3>Accessibility — what the browser does and what it doesn’t</h3><p>The API handles focus management and keyboard interactions out of the box, which is genuinely great. But popover has <strong>no inherent semantics</strong> — it&#39;s just a floating div. You still need to bring your own ARIA depending on what you&#39;re building. A popover being used as a menu needs role=&quot;menu&quot;, a tooltip needs role=&quot;tooltip&quot;, and so on. Don&#39;t assume the API covers the semantics side because it doesn&#39;t.</p><p>The Popover API won’t change your life but it will quietly retire a chunk of boilerplate you’ve been copy-pasting for years. Focus management, top layer stacking, light-dismiss, keyboard handling — all gone from your to-do list. Just make sure you still own the semantics side, and you’re good. if you have read this far I would like to thank you for your curiosity and you should do the same (smiley emoji).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f44ba7e7aeff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leverage the power of  :has() in CSS]]></title>
            <link>https://medium.com/@abhijitkhatua/leverage-the-power-of-has-in-css-07d5c8a776ba?source=rss-51156271a57c------2</link>
            <guid isPermaLink="false">https://medium.com/p/07d5c8a776ba</guid>
            <category><![CDATA[css3]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Abhijit]]></dc:creator>
            <pubDate>Wed, 18 Sep 2024 23:05:33 GMT</pubDate>
            <atom:updated>2024-09-18T23:05:33.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OSDQUsyVjLzzokkkeyhZ5A.jpeg" /></figure><h3>Leverage the power of :has() in CSS</h3><p>The CSS and other web standards are ever-changing fields and now more than ever, we as homo-sapiens also need to evolve and survive in these ever-changing fields as Grandpa once said.</p><blockquote>It is not the strongest of the species that survives, nor the most intelligent that survives. It is the one that is the most adaptable to change — Charles Darwin</blockquote><p>now if you are ready to adapt to the changes and evolve to new heights then let&#39;s start the journey with me, I will tell you how learning some web standards can make your life easier faster, and better.</p><p>If you are interested in knowing about :has() selector I guess you know about the CSS combinators &amp; pseudo-classes already if not don’t worry, I&#39;ll get you covered.</p><h3>Combinators :</h3><p>So basically when you need to target a specific HTML element in CSS you can do it by targeting its tag name or giving it an ID or class that much you know obviously, but when it comes to targeting an element that is relative to another element we need combinators.</p><p>e.g.-:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*b7otissiptwmJQ1gLRk53A.gif" /></figure><p>here in this scenario, you have an input field and a search icon to the right and all you want to do is change the style of the icon based on the input field let&#39;s say you want to change the icon color to red when the input is in focus, you can do that by writing a bunch of js if you are a maniac or you can do that using combinators easily.</p><pre>input:focus + .icon-search {<br>color: red;<br>}</pre><p>cool huh, now let&#39;s know about what other types of combinators exist.</p><p>There are four different combinators in CSS:</p><ul><li>descendant selector (space)</li><li>child selector (&gt;)</li><li>adjacent sibling selector (+) the one we just used</li><li>general sibling selector (~)</li></ul><ol><li>The descendant selector matches all elements that are descendants of a specified element.</li><li>The child selector selects all elements that are the children of a specified element.</li><li>The adjacent sibling selector is used to select an element that is directly after another specific element. Sibling elements must have the same parent element, and “adjacent” means “immediately following”.</li><li>The general sibling selector selects all elements that are the next siblings of a specified element.</li></ol><p>okay, I can go further and explain it in detail but this article is not about the combinators so I’ll skip if you are still confused about combinators please check this mdn doc -: <a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Combinators">https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Combinators</a></p><h3>What :has() has to offer better?</h3><p>Well from a user perspective, nothing changes because we as a developer always find a a way around any problem that arises but not necessarily all those ways are better developer experience so : has() promises a better developer experience let&#39;s see if it is true.</p><p>before moving on let’s check the compatibility of the feature</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*m6RG3MqmBW-17FPqo11UWg.png" /><figcaption>compartibity tag by mdn accoss major browsers</figcaption></figure><p>well it’s pretty compatible as of September 2024 so yeah we are good to go.</p><p>defination -: The functional :has() CSS <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes">pseudo-class</a> represents an element if any of the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors/Selector_structure#relative_selector">relative selectors</a> that are passed as an argument match at least one element when anchored against this element. This pseudo-class presents a way of selecting a parent element or a previous sibling element with respect to a reference element by taking a <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Selector_list#relative_selector_list">relative selector list</a> as an argument. ( I just copied that from mdn ; )</p><p>if you can read and understand it then you are brilliant if not don’t worry, you are not alone that&#39;s why I’m writing this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z46l5tenvyK4mbalHWl3xQ.png" /><figcaption>Fig 3</figcaption></figure><p>Here I divided it into 3 parts 1st element 2nd has pseudoclass and the 3rd element is inside the parenthesis now what do what?</p><p>the first element is the element we want to target with the pseudoclass and the element inside the parenthesis is the argument for selecting the 1st element for example imagine having a bunch of divs some have an h1 tag inside and some have an h3 and you just want to select the divs that only have h3 inside then:-</p><pre>divs:has(h3) {<br>font-size: 14px;<br>}</pre><p>Okay, you get the general idea of how it works pretty simple.</p><p>Now let’s look at fig-3 again the 1st and 3rd parts don’t necessarily have to be an element they can be a class or ID but the 3rd part can also be an attribute, pseudo-class, and pseudo-element selector.</p><p>Let’s take the same search example we took before with a little tweak, instead of the input immediately followed by the icon we reverse it, now if I tell you to change the color based on the focus pseudoclass, can you? (give it a try).</p><p>if you did it, well done but I&#39;m pretty sure it wasn&#39;t that easy for you because, without the :has() pseudo-class, you cannot use CSS selectors to select a preceding sibling of a different type or a parent element. Now let’s see how we can do that with :has().</p><pre>.icon-search:has(+ input:focus) {<br>  color:red;<br>}</pre><p>In this code the :has()selects the element with class icon-seach that is immediately followed by an input element and if the input is focused then execute the following CSS See no more JS easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*FfblyV-54yHGee4xc79Vlw.gif" /></figure><p>if you are good up until now let’s explore more hard stuff that we can with :has() .</p><h3>Logical Operations :</h3><p>The :has() relational selector can be used to check if one of the multiple features is true or if all the features are true.</p><p>By using comma-separated values inside the :has() relational selector, you are checking to see if any of the parameters exist. x:has(a, b) will style x if descendant a OR b exists.</p><p>By chaining together multiple :has() relational selectors together, you are checking to see if all of the parameters exist. x:has(a):has(b) will style x if descendant a AND b exist.</p><pre>body:has(video, audio) {<br>  /* styles to apply if the content contains audio OR video */<br>}<br>body:has(video):has(audio) {<br>  /* styles to apply if the content contains both audio AND video */<br>}</pre><h4>Has with :not()</h4><p>You can also combine the :has() with :not() where you don’t select the element when it meets the criteria example :-</p><pre>.icon-search:has(+ :not(input:focus)){<br>  color : red;<br>}</pre><p>now this code will reverse what we did earlier means making the icon red only when it&#39;s not in focus.</p><h4>With Attributes</h4><p>You can pass attributes as conditions in :has() you do some crazy stuff like this</p><pre>.icon-search:has(+ input[type=search]){<br>  color : red;<br>}</pre><p>or</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>  &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css&quot;&gt;<br>  &lt;title&gt;Searchbar&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;div&gt;<br>    &lt;i id=&quot;icon-search&quot; class=&quot;fa fa-search&quot;&gt;&lt;/i&gt;<br>    &lt;input type=&quot;search&quot;  placeholder=&quot;search&quot;&gt;<br>   &lt;/div&gt;<br>  &lt;div&gt;<br>    &lt;i id=&quot;icon-search&quot; class=&quot;fa fa-search&quot;&gt;&lt;/i&gt;<br>    &lt;input style=&quot;border: 1px solid red;&quot; type=&quot;search&quot;  placeholder=&quot;search&quot;&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><pre>#icon-search:has(+ input[style=&quot;border: 1px solid red;&quot;]){<br>  color : red;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*UvZgZ1juLBWUdbnbMknH1A.png" /></figure><p>You can use the above code inside a code pen to play around and get the idea.</p><p>*Another bonus tip is after using :has() you can also use combinators to get the desired result for example element:has(element)+.element{style} in the previous example of an icon and input it selects the input as normal CSS does with combinators.</p><p>I just explained :has() with the simplest example possible to you and of course, the applications it can be used and the ways it can unfold can be enormous and up to your creativity. If you have read this far I would like to thank you for your perseverance and you may achieve great heights in life.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07d5c8a776ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>