Introduction
Landing pages are a critical aspect of web design, often serving as the first point of contact for visitors. In this article, we’ll explore how you can take your landing page design to the next level using 3D elements and animations. We’ll use HTML, CSS, and JavaScript—with the powerful GSAP library for smooth animations—to create an eye-catching and interactive 3D landing page.
By the end of this article, you’ll be equipped with the knowledge to build a unique landing page that not only engages users but also offers a smooth, interactive experience.
Technologies Used
We’ll focus on three key technologies:
- HTML for the structure of the page.
- CSS for styling and layout.
- GSAP (GreenSock Animation Platform) to add motion and interactivity to the elements.
HTML Structure
We’ll begin by building the foundation of the landing page using HTML. The HTML is relatively straightforward, but it’s essential to structure the page correctly to ensure that our animations and interactivity work smoothly.
Here’s a basic HTML structure for the page:
SVG Illustration - Section transition (gamma.app)
A new medium for
presenting ideas.
(scroll further)
Open the door
to a new universe
(click to pause the ball)
Explanation of the Key Elements:
- Google Fonts: We use the Abhaya Libre font from Google Fonts to create an elegant and stylish typography for the landing page.
- SVG Element: The ball is created using an SVG element, which allows for flexible scaling and perfect rendering. We use the
<circle>
element within the SVG to define the ball. - Section Element: The entire landing page content is wrapped inside a
<section>
tag, which helps with layout management and allows for easy application of styling and animations later on.
CSS for Styling and Layout
Now that the HTML structure is in place, it’s time to bring it to life with some styling. We’ll use CSS to style the page, set the layout, and apply gradients and animations.
@import url('https://fonts.googleapis.com/css2?family=Abhaya+Libre:wght@400;500;600;700;800&display=swap');
html, body {
margin:0;
padding:0;
width:100%;
height:100%;
font-family: "Abhaya Libre", serif;
font-weight: 600;
font-style: normal;
}
main {
display:flex;
justify-content:center;
flex-direction:column;
}
section {
display:flex;
align-items:center;
justify-content:center;
width:100%;
min-height:100vh;
}
#s2 {
background:#1d0042;
}
svg {
position:relative;
margin-top:-9vw;
}
h1 {
font-size:clamp(3vw, 8.5vw, 99px);
text-align:center;
}
#s1 h1 {
font-weight:800;
}
.pink {
color:rgb(239, 208, 255);
display:block;
}
.radial {
-webkit-text-fill-color: transparent;
background-image: radial-gradient(circle at -20% 0, #2b0aff, #e93abf 31%, #f658a8 48%, #febf72);
-webkit-background-clip: text;
background-clip: text;
display: block;
}
.smaller {
font-size:0.35em;
font-weight:500;
}
Key Points:
- Responsive Typography: The
font-size
of the title is controlled usingclamp()
, which ensures that the font is responsive across devices. It adjusts based on the viewport width (vw
). - Gradients: We apply a linear gradient to the text in the
.title
class, giving it a dynamic, multi-colored effect. Thebackground-clip
and-webkit-text-fill-color
properties make sure the gradient fills only the text area, while the actual text remains transparent. - SVG Ball: The ball is sized at 100x100px and positioned with CSS. We keep the ball’s position
relative
, so we can move it smoothly later using JavaScript.
JavaScript Animations Using GSAP
With the HTML and CSS done, we can now add the real magic: animations. GSAP is a robust JavaScript animation library that allows you to create smooth, high-performance animations. Here, we’ll animate the ball and make it follow a circular path.
const ballTL = gsap.timeline({repeat:-1, defaults:{duration:2, ease:'none'}})
.to('#b1', {
scale:0.75,
motionPath:{
path: "#b1Path",
align: "#b1Path",
start: 0.25,
end: 0.75
}}, 0)
.add(()=>document.querySelector('.mg-back').append(document.querySelector('#b1')), 1)
.to('#b1', {
scale:1,
motionPath:{
path: "#b1Path",
align: "#b1Path",
start: 0.75,
end: 1.25
}}, 2)
.add(()=>document.querySelector('.mg-front').append(document.querySelector('#b1')), 3)
.to('#b1-dark', {scaleY:0.8, ease:'sine.inOut', transformOrigin:'88% 80%', yoyo:true, repeat:1}, 0)
.to('#b1 ellipse', {scale:0.6, ease:'sine.inOut', transformOrigin:'0 50%', yoyo:true, repeat:1}, 0)
.timeScale(0.25)
window.onclick = ()=> ballTL.isActive()? ballTL.pause() : ballTL.play() //toggle play on click
gsap.timeline({
scrollTrigger:{
trigger:'#s1',
start:'0 0',
endTrigger:'#s2',
end:'0 0',
scrub:0.1
}
})
.to('.ring2', {y:99, scaleY:1.08}, 0)
.fromTo('.ring1', {y:2},{y:60, skewY:3}, 0)
// .from('svg', {attr:{viewBox:'1 0 999 200'}}, 0)
Key Points:
- Ball Animation: Using
motionPath
, we define the path for the ball. Thecurviness
parameter gives the path a smooth curve, andautoRotate
ensures that the ball rotates as it follows the path. - ScrollTrigger: The title text scales up as the user scrolls down the page, creating an interactive experience where elements respond to user actions.
- When the user clicks anywhere on the landing page, the ball animation toggles between
pause()
andplay()
. This small touch of interactivity can significantly enhance user engagement.
Optimizing Performance
While animations and 3D effects are visually appealing, it’s essential to optimize them to prevent performance issues, especially on mobile devices. Here are a few tips:
- Use SVGs for Vector Graphics: SVGs scale beautifully without losing quality, and they are lightweight compared to image formats like PNG or JPG.
- Keep JavaScript Lightweight: Only load the libraries you need (in this case, GSAP) and avoid overloading your page with heavy scripts.
- Leverage Hardware Acceleration: GSAP automatically takes advantage of hardware acceleration, but you can further optimize by ensuring that CSS properties like
transform
are used instead oftop
/left
.
Video Preview Of 3D Landing Page
Conclusion
In this article, we’ve built a stunning 3D landing page that combines the power of HTML, CSS, and JavaScript with GSAP for animations. By integrating responsive design, scroll-triggered animations, and interactive elements, we’ve created a landing page that offers a dynamic and engaging user experience.
Feel free to take the concepts from this tutorial and experiment with your own designs—there’s no limit to what you can achieve with these tools!