GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.w3schools.com — CSS 3D Transforms - 3D Carousel
❮
❯
CSS TutorialCSS HOME CSS Introduction CSS Syntax CSS Selectors CSS How To CSS Comments CSS Errors CSS Colors CSS Backgrounds
Background Color
Background Image
Background Repeat
Background Attachment
Background Shorthand
Code Challenge
CSS Borders
CSS Margins
CSS Padding
CSS Height / Width
CSS Box Model
CSS Outline
CSS Text
Text Color
Text Alignment
Text Decoration
Text Decoration Styles
Text Transformation
Text Spacing
Text Shadow
Code Challenge
CSS Fonts
Font Family
Font Web Safe
Font Fallbacks
Font Style
Font Size
Font Google
Font Pairings
Font Shorthand
Code Challenge
CSS Icons
CSS Links
CSS Lists
CSS Tables
CSS Display
CSS Max-width
CSS Position
CSS Position Offsets
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Opacity
CSS Navigation Bars
CSS Dropdowns
CSS Image Gallery
CSS Image Sprites
CSS Attribute Selectors
CSS Forms
CSS Counters
CSS Units
CSS Inheritance
CSS Specificity
CSS !important
CSS Math Functions
CSS Optimization
CSS Accessibility
CSS Website Layout
CSS AdvancedCSS Rounded Corners CSS Border Images CSS Backgrounds CSS Colors CSS Gradients CSS Shadows CSS Text Effects CSS Custom Fonts CSS 2D Transforms CSS 3D Transforms CSS Transitions CSS Animations CSS Tooltips CSS Image Styling CSS Image Modal CSS Image Centering CSS Image Filters CSS Image Shapes CSS object-fit CSS object-position CSS Masking CSS Buttons CSS Pagination CSS Multiple Columns CSS User Interface CSS Variables CSS @property CSS Box Sizing CSS Functions CSS Media QueriesCSS FlexboxFlexbox Intro Flex Container Flex Items Flex ResponsiveCSS GridGrid Intro Grid Container Grid Items Grid 12-column Layout CSS @supportsCSS ResponsiveRWD Intro RWD Viewport RWD Grid View RWD Media Queries RWD Images RWD Videos RWD Frameworks RWD TemplatesCSS CertCSS CertificateCSS SASSSASS TutorialCSS ExamplesCSS Templates CSS Examples CSS Videos CSS Editor CSS Snippets CSS Quiz CSS Exercises CSS Code Challenges CSS Website CSS Syllabus CSS Study Plan CSS Interview PrepCSS ReferencesCSS Reference CSS Selectors CSS Combinators CSS Pseudo-classes CSS Pseudo-elements CSS At-rules CSS Functions CSS Reference Aural CSS Web Safe Fonts CSS Animatable CSS Units CSS PX-EM Converter CSS Colors CSS Color Values CSS Default Values CSS Browser SupportCSS 3D Transforms - 3D Carousel
Share
CSS - A Rotating 3D CarouselHere we demonstrate how to make another classic 3D object: A rotating carousel. 1
2
3
4
5
6
The HTML StructureLet's start with the basic HTML structure:
<div class="container">
<div class="carousel"> <div class="card" style="--index:0;">1</div> <div class="card" style="--index:1;">2</div> <div class="card" style="--index:2;">3</div> <div class="card" style="--index:3;">4</div> <div class="card" style="--index:4;">5</div> <div class="card" style="--index:5;">6</div> </div> </div> The The CSS StylingFirst, we define some variables in the The radius has the following formula: radius = (width / 2) / tan(360 / quantity / 2). For 6 card items of 200px width: (200 / 2) / tan(360 / 6 / 2) = 100 / 0.577 = ~173px. We set --radius to 173px;
:root {
--card-width: 200px; --card-height: 300px; --total-items: 6; --radius: 173px; /* Calculated radius for 6 cards */ } Next, we define the 3D container box: Apply
.container {
width: var(--card-width); height: var(--card-height); margin: 80px auto; perspective: 1000px; } Now the
.carousel {
width: 100%; height: 100%; position: relative; transform-style: preserve-3d; animation: spin 20s infinite linear; } Then, we add some base styling for all six cards. To position the cards in 3D space, we will need to reset their positions in 2D with position: absolute:. Then we use rotateY() to rotate each card, and translateZ() to push it out to form the cylinder edge:
.card {
position: absolute; width: 100%; height: 100%; left: 0; top: 0; background: linear-gradient(to bottom, red, yellow); color: white; font-size: 2rem; display: flex; align-items: center; justify-content: center; border-radius: 10px; transform: rotateY(calc(var(--index) * (360deg / var(--total-items)))) translateZ(var(--radius)); } Then, we create the keyframe animation to rotate the carousel:
@keyframes spin {
from { transform: rotateY(0deg); } to { transform: rotateY(360deg); } } At the end, we create a pause on hover for easier viewing:
.carousel:hover {
animation-play-state: paused; } Full Example of Rotating 3D CarouselHere is the full example of the rotating 3D carousel: Example
:root {
Try it Yourself »
--card-width: 200px; --card-height: 200px; --total-items: 6; --radius: 173px; /* Calculated radius for 6 cards */ } .container { width: var(--card-width); height: var(--card-height); margin: 80px auto; perspective: 1000px; } .carousel { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; animation: spin 20s infinite linear; } .card { position: absolute; width: 100%; height: 100%; left: 0; top: 0; background: linear-gradient(to bottom, red, yellow); color: white; font-size: 2rem; display: flex; align-items: center; justify-content: center; border-radius: 10px; transform: rotateY(calc(var(--index) * (360deg / var(--total-items)))) translateZ(var(--radius)); } @keyframes spin { from { transform: rotateY(0deg); } to { transform: rotateY(360deg); } } .carousel:hover { animation-play-state: paused; } Free account Track your progress
XP earned 0
Day streak 0
Spaces 0
League —
New Learn in Adventure Mode W3Schools Adventure AppCoding fundamentals as bite-sized lessons and challenges.
×
Contact SalesIf you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: Report ErrorIf you want to report an error, or if you want to make a suggestion, send us an e-mail: Top TutorialsHTML TutorialCSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial Top ReferencesHTML ReferenceCSS Reference JavaScript Reference SQL Reference Python Reference W3.CSS Reference Bootstrap Reference PHP Reference HTML Colors Java Reference AngularJS Reference jQuery Reference
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy. Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |