{"id":270,"date":"2026-11-22T05:04:54","date_gmt":"2026-11-22T05:04:54","guid":{"rendered":"https:\/\/webdevpuneet.com\/blog\/?p=270"},"modified":"2026-11-22T05:05:08","modified_gmt":"2026-11-22T05:05:08","slug":"5-modern-css-features-that-replace-javascript-with-copy-paste-demos","status":"publish","type":"post","link":"https:\/\/webdevpuneet.com\/blog\/5-modern-css-features-that-replace-javascript-with-copy-paste-demos\/","title":{"rendered":"5 Modern CSS Features That Replace JavaScript (With Copy-Paste Demos)"},"content":{"rendered":"<p><!--\n================================================================\n  POST TITLE (paste into the WordPress title field \u2014 it becomes the page H1)\n  5 Modern CSS Features That Replace JavaScript (With Copy-Paste Demos)\n\n  SEO TITLE (57 chars, target 50\u201360, max 60 \u2014 \"Optimize SEO\" panel \u2192 SEO TITLE)\n  5 Modern CSS Features That Replace JavaScript: Live Demos\n\n  SEO DESCRIPTION (157 chars, target 150\u2013160, max 160 \u2014 \"Optimize SEO\" panel \u2192 SEO DESCRIPTION)\n  Native carousel dots, animated dialogs, auto-growing textareas, height auto accordions and squircle corners: five new CSS features with free copy-paste code.\n\n  IMAGES: the 5 pictures below load straight from webdevpuneet.com\/images\/ui-snippets\/previews\/ (same domain, no upload needed).\n  They and the 5 snippet links only work once the latest site build (2026-11-21 snippets) is deployed and live.\n\n  HOW TO PASTE: click the first line after this comment, press Ctrl+Shift+End, Ctrl+C.\n  In WordPress click \"Type \/ to choose a block\", then Ctrl+V.\n  Fallback: \u22ee menu \u2192 Code editor \u2192 paste.\n================================================================\n--><\/p>\n\n\n<p class=\"wp-block-paragraph\">For years, five very ordinary jobs on a web page needed JavaScript: dots under a carousel, a modal that fades out, a textarea that grows, an accordion that opens to its real height, and a button with properly smooth corners. Each one had a library, a snippet from a forum, or a hack with a made-up number in it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the last two years browsers have quietly added a CSS feature for every one of them. Support is not equal yet, so each demo below detects the feature and falls back sensibly. I built all five as free, editable snippets in the <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/\" target=\"_blank\" rel=\"noopener\">UI Snippets library<\/a>. Open one, read the code, copy it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The five at a glance<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#carousel\"><strong>Carousel dots and arrows<\/strong><\/a> from <code>::scroll-marker<\/code> and <code>::scroll-button<\/code>.<\/li>\n\n\n\n<li><a href=\"#dialog\"><strong>Animated dialog and popover<\/strong><\/a> with <code>@starting-style<\/code>.<\/li>\n\n\n\n<li><a href=\"#textarea\"><strong>Auto-growing textarea<\/strong><\/a> with <code>field-sizing: content<\/code>.<\/li>\n\n\n\n<li><a href=\"#accordion\"><strong>Accordion that animates to height: auto<\/strong><\/a> with <code>interpolate-size<\/code>.<\/li>\n\n\n\n<li><a href=\"#squircle\"><strong>Squircle corners<\/strong><\/a> with <code>corner-shape<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 id=\"carousel\" class=\"wp-block-heading\">1. A carousel with no carousel code<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/css-native-carousel-scroll-markers\/\" target=\"_blank\" rel=\"noopener\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/webdevpuneet.com\/images\/ui-snippets\/previews\/css-native-carousel-scroll-markers.png?w=1080&#038;ssl=1\" alt=\"CSS carousel with generated arrows and a pill-shaped active dot, built without JavaScript\" style=\"width:560px;height:auto\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A scroll container with <code>scroll-snap-type<\/code> was always a decent swipeable carousel. What it lacked was controls. Chrome 135 added two pseudo-elements that generate them: a <code>::scroll-marker<\/code> dot for every slide, and <code>::scroll-button()<\/code> arrows that scroll one page and disable themselves at the ends. The active dot is styled with <code>:target-current<\/code>, so you can stretch it into a pill with a transition.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.carousel { scroll-marker-group: after; scroll-snap-type: x mandatory; }\n.slide::scroll-marker { content: ''; width: 12px; height: 12px; }\n.slide::scroll-marker:target-current { width: 34px; }\n.carousel::scroll-button(inline-end) { content: '\u2192' \/ 'Next slide'; }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The text after the slash is the accessible name, so a screen reader says &#8220;Next slide&#8221; and not &#8220;right arrow&#8221;. In browsers without support the snippet reveals two ordinary buttons; the swiping works everywhere. <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/css-native-carousel-scroll-markers\/\" target=\"_blank\" rel=\"noopener\">Open the carousel snippet<\/a>.<\/p>\n\n\n\n<h2 id=\"dialog\" class=\"wp-block-heading\">2. A dialog that fades out as well as in<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/starting-style-animated-dialog-popover\/\" target=\"_blank\" rel=\"noopener\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/webdevpuneet.com\/images\/ui-snippets\/previews\/starting-style-animated-dialog-popover.png?w=1080&#038;ssl=1\" alt=\"Buttons that open an animated native dialog and a share popover menu\" style=\"width:560px;height:auto\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A native <code>&lt;dialog&gt;<\/code> is <code>display: none<\/code> when closed, and you cannot transition from <code>none<\/code>. Two features fix both directions. <code>@starting-style<\/code> gives the element a first-frame look to animate from when it appears. <code>transition-behavior: allow-discrete<\/code> on <code>display<\/code> and <code>overlay<\/code> keeps it on screen until the fade-out ends.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dialog { opacity: 0; transform: scale(.96);\n  transition: opacity .28s, transform .28s,\n              overlay .28s allow-discrete, display .28s allow-discrete; }\ndialog&#91;open] { opacity: 1; transform: none; }\n@starting-style { dialog&#91;open] { opacity: 0; transform: scale(.96); } }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You keep everything the platform gives you for free: focus trapping, Escape to close, an inert page behind. The same recipe animates a <code>popover<\/code> menu, and the demo anchors it under its button. <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/starting-style-animated-dialog-popover\/\" target=\"_blank\" rel=\"noopener\">Open the dialog snippet<\/a>.<\/p>\n\n\n\n<h2 id=\"textarea\" class=\"wp-block-heading\">3. A textarea that grows by itself<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/auto-growing-textarea-field-sizing\/\" target=\"_blank\" rel=\"noopener\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/webdevpuneet.com\/images\/ui-snippets\/previews\/auto-growing-textarea-field-sizing.png?w=1080&#038;ssl=1\" alt=\"Chat message composer with a one-line textarea that grows as you type\" style=\"width:560px;height:auto\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Every chat box and AI prompt field starts at one line and grows. The old fix reset the height and copied <code>scrollHeight<\/code> on every keystroke. Now it is one declaration, and <code>lh<\/code> units cap it in lines instead of pixels.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>textarea { field-sizing: content; min-height: 1lh; max-height: 9lh; }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That is the whole feature. The snippet wraps it in a message composer where Enter sends, Shift+Enter adds a line, and a Firefox fallback copies <code>scrollHeight<\/code> because Firefox has not shipped it yet. <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/auto-growing-textarea-field-sizing\/\" target=\"_blank\" rel=\"noopener\">Open the textarea snippet<\/a>.<\/p>\n\n\n\n<h2 id=\"accordion\" class=\"wp-block-heading\">4. An accordion that opens to its real height<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/animated-details-accordion-auto-height\/\" target=\"_blank\" rel=\"noopener\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/webdevpuneet.com\/images\/ui-snippets\/previews\/animated-details-accordion-auto-height.png?w=1080&#038;ssl=1\" alt=\"FAQ accordion built from details elements with one answer open\" style=\"width:560px;height:auto\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;How do I animate height: auto&#8221; has been asked for fifteen years, and the answers were all workarounds. <code>interpolate-size: allow-keywords<\/code> lets the browser interpolate between <code>0<\/code> and <code>auto<\/code>, and <code>::details-content<\/code> exposes the part of a <code>&lt;details&gt;<\/code> that collapses. Give several <code>&lt;details&gt;<\/code> the same <code>name<\/code> and they become an exclusive accordion without a click handler.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:root { interpolate-size: allow-keywords; }\ndetails::details-content { block-size: 0; transition: block-size .35s, content-visibility .35s allow-discrete; }\ndetails&#91;open]::details-content { block-size: auto; }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It works in Chrome and Edge now; elsewhere the items still open and close, just without the animation. The answers stay plain text in the HTML, which suits an FAQ page. <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/animated-details-accordion-auto-height\/\" target=\"_blank\" rel=\"noopener\">Open the accordion snippet<\/a>.<\/p>\n\n\n\n<h2 id=\"squircle\" class=\"wp-block-heading\">5. Squircle corners in one property<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/squircle-corner-cards-buttons\/\" target=\"_blank\" rel=\"noopener\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/webdevpuneet.com\/images\/ui-snippets\/previews\/squircle-corner-cards-buttons.png?w=1080&#038;ssl=1\" alt=\"Two cards compared: a normal rounded corner and a CSS squircle corner\" style=\"width:560px;height:auto\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>border-radius<\/code> joins a circular arc to a flat edge, and your eye can pick out where. A squircle, the shape of an app icon, eases the curve into the edge. Designers faked it with SVG masks, which also cut off shadows and focus rings. <code>corner-shape<\/code> changes the border box itself, so shadows and outlines follow.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.card { border-radius: 48px; corner-shape: squircle; }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It is new (Chrome and Edge 139), and unsupported browsers just keep the normal rounded corner, so it is a safe upgrade. The demo has a slider so you can see the difference between the two curves grow as the radius grows. <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/squircle-corner-cards-buttons\/\" target=\"_blank\" rel=\"noopener\">Open the squircle snippet<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to use them safely<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Detect, do not assume.<\/strong> <code>CSS.supports()<\/code> and <code>@supports<\/code> tell you what the browser understands. Every snippet here uses one.<\/li>\n\n\n\n<li><strong>Make the fallback acceptable.<\/strong> A carousel without arrows still swipes, an accordion without animation still opens, a squircle without support is a rounded corner.<\/li>\n\n\n\n<li><strong>Keep the native behaviour.<\/strong> Dialog focus trapping, details semantics and button names are what you get from the platform. Do not rebuild them.<\/li>\n\n\n\n<li><strong>Respect reduced motion.<\/strong> All five turn their transitions off under <code>prefers-reduced-motion<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Are these safe to use in production today?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, as progressive enhancements. Each feature degrades to something that still works: swipe without arrows, instant open and close, a normal rounded corner. Do not rely on them for anything a visitor must see, only for polish.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Which browsers support them?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Chrome and Edge support all five at the versions mentioned above. <code>@starting-style<\/code> and dialog transitions also work in Safari and recent Firefox, <code>field-sizing<\/code> is in Safari but not Firefox yet, and the rest are Chromium first. Check the support note inside each demo.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I copy the code for client work?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Every snippet shows its HTML, CSS and JavaScript, which you can copy, edit and use in your own and your clients&#8217; projects, and each has an AI prompt if you would like an assistant to adapt it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Try them in the browser:<\/strong> <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/css-native-carousel-scroll-markers\/\" target=\"_blank\" rel=\"noopener\">carousel<\/a>, <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/starting-style-animated-dialog-popover\/\" target=\"_blank\" rel=\"noopener\">dialog and popover<\/a>, <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/auto-growing-textarea-field-sizing\/\" target=\"_blank\" rel=\"noopener\">textarea<\/a>, <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/animated-details-accordion-auto-height\/\" target=\"_blank\" rel=\"noopener\">accordion<\/a> and <a href=\"https:\/\/webdevpuneet.com\/ui-snippets\/squircle-corner-cards-buttons\/\" target=\"_blank\" rel=\"noopener\">squircle corners<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For years, five very ordinary jobs on a web page needed JavaScript: dots under a carousel, a modal that fades out, a textarea that grows, an accordion that opens to its real height, and a button with properly smooth corners. Each one had a library, a snippet from a forum, or a hack with a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":271,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","advanced_seo_description":"Native carousel dots, animated dialogs, auto-growing textareas, height auto accordions and squircle corners: five new CSS features with free copy-paste code.","jetpack_seo_html_title":"5 Modern CSS Features That Replace JavaScript: Live Demos","jetpack_seo_noindex":false,"jetpack_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"5 modern CSS features that can replace JavaScript!\n\nExplore native carousel dots, animated dialogs, auto-growing textareas, smooth accordion transitions and squircle corners. \n\nTry live demos and copy the code for free!\n\n#CSS #JavaScript #WebDevelopment #FrontendDevelopment #CSSAnimation #WebDesign #Coding","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[14],"tags":[],"class_list":["post-270","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ui-snippets","et-has-post-format-content","et_post_format-et-post-format-standard"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/phrh5V-4m","jetpack_featured_media_url":"https:\/\/i0.wp.com\/webdevpuneet.com\/blog\/wp-content\/uploads\/2026\/11\/modern-css-5-snippets-featured.jpg?fit=1200%2C630&ssl=1","_links":{"self":[{"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/posts\/270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/comments?post=270"}],"version-history":[{"count":2,"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/posts\/270\/revisions"}],"predecessor-version":[{"id":273,"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/posts\/270\/revisions\/273"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/media\/271"}],"wp:attachment":[{"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/media?parent=270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/categories?post=270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webdevpuneet.com\/blog\/wp-json\/wp\/v2\/tags?post=270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}