惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
S
Security Affairs
阮一峰的网络日志
阮一峰的网络日志
L
LangChain Blog
Microsoft Azure Blog
Microsoft Azure Blog
雷峰网
雷峰网
Recent Announcements
Recent Announcements
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
博客园_首页
The Cloudflare Blog
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
S
SegmentFault 最新的问题
P
Proofpoint News Feed
Y
Y Combinator Blog
Jina AI
Jina AI
博客园 - 聂微东
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
F
Full Disclosure
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
T
Tailwind CSS Blog
J
Java Code Geeks
Vercel News
Vercel News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
小众软件
小众软件
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Blog of Author Tim Ferriss
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 三生石上(FineUI控件)
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
Attack and Defense Labs
Attack and Defense Labs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
宝玉的分享
宝玉的分享
IT之家
IT之家
Hacker News: Ask HN
Hacker News: Ask HN
The Register - Security
The Register - Security
T
The Exploit Database - CXSecurity.com
T
Threat Research - Cisco Blogs

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
CSS Carousels With Zero JavaScript: 5 Patterns
RAXXO Studio · 2026-05-27 · via DEV Community
  • A scroll-snap track plus the new pseudo-elements replaced a 14KB carousel dependency in my UI.

  • scroll-marker-group and ::scroll-marker render the dot navigation with no script and free keyboard support.

  • ::scroll-button() draws working previous and next buttons that disable themselves at each end.

  • Numbered markers, peeking layouts, and an @supports query round out a fallback-safe carousel.

I pulled a 14KB carousel dependency out of a storefront last week and replaced it with roughly 40 lines of CSS. No JavaScript, no hydration step, no layout shift while a script boots. The browser now owns the dots, the arrows, and the keyboard handling, and it does all three more accessibly than the plugin did. Here are the five patterns I used, built on CSS features that shipped across 2025 and 2026.

Pattern 1: The Scroll-Snap Track That Does the Heavy Lifting

Every carousel should start as a scrollable, snapping track. This part has worked for years, and it is the accessible default: a region you can swipe on touch, scroll with a trackpad, and tab into with a keyboard.


.carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
}
.carousel > * {
  flex: 0 0 100%;
  scroll-snap-align: center;
}

Enter fullscreen mode Exit fullscreen mode

scroll-snap-type: x mandatory forces each item to settle into place. Switch to proximity if you want snapping only when the user lands close to an edge, which feels better for long, free-scrolling galleries. scroll-snap-align: center decides where each slide parks. That is a complete, usable carousel already, before a single control, and it degrades to a plain scroll region on any browser made in the last decade. The 2026 pieces all attach to this same track, which is why getting the foundation right matters more than the decoration. If scroll behaviour is your thing, I went deeper on it in scroll-driven animations.

One structural note before the controls: the marker and button pseudo-elements attach to the scroll container and its direct children, so mark up the slides as a list. A `

of - slides gives you the right semantics and the right elements for ::scroll-marker` to hang off, and the markup still means something when the CSS is stripped or fails to load.

Pattern 2: Dot Navigation With scroll-marker-group

The dots used to be a JavaScript job: track the active index, render a button per slide, and wire each click back to a scroll. Now the scroll container generates them for you.


.carousel { scroll-marker-group: after; }

.carousel > li::scroll-marker {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  background: #2a2a2c;
}
.carousel > li::scroll-marker:target-current {
  background: #e3fc02;
}
.carousel::scroll-marker-group {
  display: flex;
  gap: 8px;
  justify-content: center;
}

Enter fullscreen mode Exit fullscreen mode

scroll-marker-group: after tells the container to emit a group of markers after the content. Each child gets a ::scroll-marker pseudo-element, and :target-current matches whichever marker maps to the slide currently in view, so the active dot lights up with no state to manage. Clicking a marker scrolls to its item. Arrow keys move between markers as a single focus group, and the group itself is one tab stop, which is exactly the keyboard model the accessibility guidelines ask for. There is no index variable, no event listener, and no ARIA to hand-roll, because the browser already knows which slide is showing.

Placement is a one-line decision. scroll-marker-group: after drops the dots below the track, before puts them above, and you style ::scroll-marker-group like any flex container to position and space them. Because the group is a single focus stop with arrow-key movement between markers, you get the keyboard pattern assistive tech expects, which is the part hand-rolled carousels almost always get wrong.

Pattern 3: Previous and Next Buttons With ::scroll-button()

::scroll-button() generates real buttons bound to the scroll position. You pass a direction, and the browser disables the button automatically when scrolling that way is no longer possible. That single behaviour kills the most common carousel bug, where the next arrow stays clickable past the final slide and the track jiggles against its edge.


.carousel::scroll-button(inline-start) {
  content: "\2039" / "Previous slide";
}
.carousel::scroll-button(inline-end) {
  content: "\203A" / "Next slide";
}
.carousel::scroll-button(*):disabled {
  opacity: 0.4;
  cursor: default;
}

Enter fullscreen mode Exit fullscreen mode

The text after the slash in content is the accessible name, so a screen reader announces "Previous slide" rather than a stray glyph. Logical directions like inline-start and inline-end follow the writing mode, so a right-to-left layout flips the arrows correctly with no extra code. These buttons are focusable and keyboard-operable the moment they exist, and the :disabled state is real, not a class you toggle.

If you would rather hide the arrows at the ends than dim them, target the disabled state with display: none instead of an opacity change. Either way the behaviour belongs to the browser, so it stays correct when slides are added or removed at runtime, which is exactly the situation where the old index-tracking code used to fall out of sync.

Pattern 4: Numbered and Thumbnail Markers

The default dot is a starting point, not a ceiling. Because ::scroll-marker accepts a content value, you can number the markers or drop a thumbnail into each one. Numbered markers use a counter on the track.


.carousel { counter-reset: slide; }
.carousel > li { counter-increment: slide; }
.carousel > li::scroll-marker {
  content: counter(slide);
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 9999px;
  font-size: 12px;
  color: #f5f5f7;
  background: #2a2a2c;
}

Enter fullscreen mode Exit fullscreen mode

For a thumbnail strip, set a background-image on each marker instead of a counter and size it to taste. This is the pattern that used to demand the most JavaScript, since a custom thumbnail navigator meant syncing two scrollers by hand. Here the markers stay in lockstep with the slides for free, and :target-current still highlights the active one. It is the clearest example of the platform absorbing a whole component category.

Pattern 5: Peeking Layouts That Hint at More

A carousel reads better when the next slide peeks in from the edge, because the partial slide is the affordance that tells people the row scrolls. You get it by sizing slides under 100% and adding scroll padding so the snapped item does not hug the wall.


.carousel {
  scroll-padding-inline: 24px;
  gap: 16px;
}
.carousel > * {
  flex: 0 0 80%;
  scroll-snap-align: center;
}

Enter fullscreen mode Exit fullscreen mode

Now each slide takes 80% of the track and the neighbours show at both edges. scroll-padding-inline keeps the snap point inset so the active slide sits centred with breathing room rather than flush against the container. Pair it with the markers and buttons from the earlier patterns and you have a modern, app-like carousel that never blocked the main thread to render.

Progressive Enhancement and Accessibility

Wrap the enhanced styling in a feature query so unsupported browsers fall back to the plain scrolling track instead of a broken control.


@supports selector(::scroll-marker) {
  /* dot, number, and button styling lives here */
}
@media (prefers-reduced-motion: reduce) {
  .carousel { scroll-behavior: auto; }
}

Enter fullscreen mode Exit fullscreen mode

The accessibility story is the real headline. A JavaScript carousel is usually a stack of divs with hand-written ARIA that drifts out of sync the moment state changes. These pseudo-elements are genuine controls the browser exposes to assistive technology and the keyboard by default, so you inherit focus order, announcements, and disabled states without writing any of it. The same instinct shows up in anchor positioning, where the platform absorbs work that used to need a library.

Browser Support and How I Migrated

Be honest about support and you can ship this today. The carousel pseudo-elements (::scroll-marker, scroll-marker-group, and ::scroll-button()) landed in Chrome in 2025 and are rolling through the other engines, while scroll-snap itself is universal and has been for years. That split is the whole reason the fallback is safe: a browser that does not understand the markers still renders a clean, swipeable, snapping track. The decoration degrades, the function does not.

The migration took an afternoon. I deleted the library import and its initialisation call, swapped the slider markup for a plain `

`, moved the dots and arrows into the stylesheet, and removed the resize handler the plugin needed to recompute its layout. The result is less JavaScript on the wire, no layout shift while a script boots, and a carousel that works before hydration finishes. Before shipping, tab through it once to confirm focus order and test it with reduced motion turned on, then delete the dependency for good.

Bottom Line

A scroll-snap track, ::scroll-marker for the dots, ::scroll-button() for the arrows, plus numbered markers and a peeking layout cover the vast majority of carousels with no script and noticeably better accessibility than the plugins they replace. I now reach for JavaScript only when I need autoplay, an infinite loop, or analytics on slide views, and even then it sits on top of the native track rather than replacing it.

Strip the dependency, keep the snap, and let the browser do the rest. For more patterns where CSS quietly retired a library, browse the Lab.