How to create a CSS-only animated timeline?
To create a CSS-only animation timeline, you need to first build a semantic HTML structure, and each event is represented by a div containing dots and content; 2. Use Flexbox layout and pseudo-elements to create a centered vertical line, and use @keyframes to define fadeInUp animation to achieve bottom-to-top display; 3. Use animation-delay to achieve cascading entry effect, and optionally add alternating content alignment on left and right; 4. Optional enhancements include using drawLine animation to simulate the line drawing process, hover effect and responsive adaptation; 5. Key points include using opacity and transform to ensure animation performance, adopt semantic tags and test mobile layout. Ultimately implement a smooth, accessible and easy to customize timeline without JavaScript.
Creating a CSS-only animated timeline is a great way to showcase events, milestones, or steps in a visually engaging way—without needing JavaScript. Here's how you can build one using just HTML and CSS, with smooth animations and a clean layout.

1. Structure the HTML Markup
Start with a semantic and simple HTML structure. Each timeline event goes into a list item, making it easy to style and animate.
<div class="timeline"> <div class="timeline-item"> <div class="timeline-dot"></div> <div class="timeline-content"> <h3>Event One</h3> <p>January 2023</p> <p>This is the first milestone in the timeline.</p> </div> </div> <div class="timeline-item"> <div class="timeline-dot"></div> <div class="timeline-content"> <h3>Event Two</h3> <p>March 2023</p> <p>Second key event with more details.</p> </div> </div> <div class="timeline-item"> <div class="timeline-dot"></div> <div class="timeline-content"> <h3>Event Three</h3> <p>June 2023</p> <p>Final milestone in this example timeline.</p> </div> </div> </div>
2. Style the Timeline with CSS
Now apply styles to create the vertical line, position the dots, and align the content. We'll use Flexbox for layout and @keyframes
for animation.

.timeline { position: relative; max-width: 800px; margin: 40px auto; padding: 20px 0; } /* Vertical line down the center */ .timeline::before { content: ''; position: absolute; top: 0; bottom: 0; width: 4px; background: #007bff; left: 50%; transform: translateX(-50%); } .timeline-item { display: flex; justify-content: flex-start; margin-bottom: 50px; opacity: 0; transform: translateY(30px); animation: fadeInUp 0.8s forwards; } /* Offset animation delay for each item */ .timeline-item:nth-child(1) { animation-delay: 0.3s; } .timeline-item:nth-child(2) { animation-delay: 0.6s; } .timeline-item:nth-child(3) { animation-delay: 0.9s; } /* Timeline dot */ .timeline-dot { width: 20px; height: 20px; background: #007bff; border: 4px solid #ffff; border-radius: 50%; box-shadow: 0 0 0 3px #007bff40; margin: 0 20px; align-self: center; } /* Content box */ .timeline-content { flex: 1; padding: 20px; background: #f9f9f9; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); max-width: 350px; } .timeline-content h3 { margin: 0 0 10px; color: #333; } .timeline-content p { margin: 5px 0; color: #666; font-size: 0.9em; } /* For alternating side (optional) */ .timeline-item:nth-child(odd) .timeline-content { align-self: flex-end; } .timeline-item:nth-child(even) .timeline-content { align-self: flex-start; } /* Animation keyframes */ @keyframes fadeInUp { to { opacity: 1; transform: translateY(0); } }
3. Optional Enhancements
You can make the timeline more dynamic with a few tweaks:
- Animate the line drawing : Use a pseudo-element with
height
animation. - Add hover effects : Scale the dot or lift the card on hover.
- Responsive layout : On small screens, stack everything vertically.
Example: Animate the line being drawn from top to bottom:

.timeline::after { content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 4px; background: #007bff; height: 0; animation: drawLine 1s ease-out forwards; } @keyframes drawLine { to { height: 100%; } }
4. Key Points to Remember
- Use
opacity
andtransform
for smooth, performant animations. - Stagger
animation-delay
to create a cascading effect. - Keep the structure semantic—
<ol></ol>
or<ul></ul>
can also be used instead ofdiv
s. - Test on mobile: consider switching to a single-column layout using media queries.
Basically, a CSS-only animated timeline comes down to combining layout techniques (Flexbox, positioning), pseudo-elements for the line, and subtle animations to bring it to life. No JavaScript needed, and it's fast, accessible, and easy to customize.
The above is the detailed content of How to create a CSS-only animated timeline?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

User agent stylesheets are the default CSS styles that browsers automatically apply to ensure that HTML elements that have not added custom styles are still basic readable. They affect the initial appearance of the page, but there are differences between browsers, which may lead to inconsistent display. Developers often solve this problem by resetting or standardizing styles. Use the Developer Tools' Compute or Style panel to view the default styles. Common coverage operations include clearing inner and outer margins, modifying link underscores, adjusting title sizes and unifying button styles. Understanding user agent styles can help improve cross-browser consistency and enable precise layout control.

Backdrop-filter is used to apply visual effects to the content behind the elements. 1. Use backdrop-filter:blur(10px) and other syntax to achieve the frosted glass effect; 2. Supports multiple filter functions such as blur, brightness, contrast, etc. and can be superimposed; 3. It is often used in glass card design, and it is necessary to ensure that the elements overlap with the background; 4. Modern browsers have good support, and @supports can be used to provide downgrade solutions; 5. Avoid excessive blur values and frequent redrawing to optimize performance. This attribute only takes effect when there is content behind the elements.

First, use JavaScript to obtain the user system preferences and locally stored theme settings, and initialize the page theme; 1. The HTML structure contains a button to trigger topic switching; 2. CSS uses: root to define bright theme variables, .dark-mode class defines dark theme variables, and applies these variables through var(); 3. JavaScript detects prefers-color-scheme and reads localStorage to determine the initial theme; 4. Switch the dark-mode class on the html element when clicking the button, and saves the current state to localStorage; 5. All color changes are accompanied by 0.3 seconds transition animation to enhance the user

vw and vh units achieve responsive design by associating element sizes with viewport width and height; 1vw is equal to 1% of viewport width, and 1vh is equal to 1% of viewport height; commonly used in full screen area, responsive fonts and elastic spacing; 1. Use 100vh or better 100dvh in the full screen area to avoid the influence of the mobile browser address bar; 2. Responsive fonts can be limited with 5vw and combined with clamp (1.5rem, 3vw, 3rem) to limit the minimum and maximum size; 3. Elastic spacing such as width:80vw, margin:5vhauto, padding:2vh3vw, can make the layout adaptable; pay attention to mobile device compatibility, accessibility and fixed width content conflicts, and it is recommended to give priority to using dvh first;

Theaspect-ratioCSSpropertydefinesthewidth-to-heightratioofanelement,ensuringconsistentproportionsinresponsivedesigns.1.Itisapplieddirectlytoelementslikeimages,videos,orcontainersusingsyntaxsuchasaspect-ratio:16/9.2.Commonusecasesincludemaintainingres

The:emptypseudo-classselectselementswithnochildrenorcontent,includingspacesorcomments,soonlytrulyemptyelementslikematchit;1.Itcanhideemptycontainersbyusing:empty{display:none;}tocleanuplayouts;2.Itallowsaddingplaceholderstylingvia::beforeor::after,wh

To achieve CSS element overlap, you need to use positioning and z-index attributes. 1. Use position and z-index: Set elements to non-static positioning (such as absolute, relative, etc.), and control the stacking order through z-index, the larger the value, the higher the value. 2. Common positioning methods: absolute is used for precise layout, relative is used for relatively offset and overlap adjacent elements, fixed or sticky is used for fixed positioning of suspended layers. 3. Actual example: By setting the parent container position:relative, child element position:absolute and different z-index, the card overlap effect can be achieved.

Define@keyframesbouncewith0%,100%attranslateY(0)and50%attranslateY(-20px)tocreateabasicbounce.2.Applytheanimationtoanelementusinganimation:bounce0.6sease-in-outinfiniteforsmooth,continuousmotion.3.Forrealism,use@keyframesrealistic-bouncewithscale(1.1
