Tag: rotate

Simple CSS examples for rotating elements and text — using transforms, angles, and subtle motion to add visual interest at littlecoding things.

  • Infinite Flipping Card Animation Utilizing Transform And Keyframes CSS Properties

    Infinite Flipping Card Animation Utilizing Transform And Keyframes CSS Properties

    Welcome to this article, where I will guide you through some simple steps of creating a stunning CSS infinite flipping card animation. With my easy-to-follow instructions, you’ll be able to design a beautiful and eye-catching card in no time. Don’t miss this opportunity to elevate your website and impress your audience! 😉

    Let’s proceed and direct our attention towards creating this distinctive animation!

    CSS Infinite flipping card effect animation

    The supplied HTML and SCSS (Sass) code generates a flip card that exhibits movement along both the Y and X axes. The X-axis and Y-axis represent two intersecting lines, defining the coordinates of a point in a two-dimensional space.

    Now, let’s analyze the code one step at a time:

    HTML structure

    Let’s start by examining the HTML structure. We begin by creating a container element with the class flip-wrapper. This container acts as the main hub for our animation. Inside this container, we have a special area with the class flip-card. So, now we have a parent element and a child element. The parent element is where we will build the animation while the child element is the one that determines the appearance of our animation.

    <div class="flip-wrapper">
      <div class="flip-card"></div>
    </div>
    HTML

    CSS Basic Structure

    In our CSS code example, we start by making the whole page’s background-color a shade of gray (#c3c8c3).

    Then, for the container called .flip-wrapper we decide its size by giving it a fixed width and height of 300 pixels. We also make it look circular or rounded by using the border-radius property. It’s important to mention that you can keep it square ⬛ if you prefer, but I went with the rounded look ⚫ because it helps us see clearly the effect.

    Moving on to the .flip-card element, we set its width and height to 100% as a way to cover the entire available space. We make it look nicer by giving it a linear-gradient background using white and black colors. A subtle gray shadow effect is also a nice touch, giving a sense of depth. To keep the circular style consistent, we add the inherit value to border-radius property.

    body {
      background-color: #213450; /* dark blue */
    }
    
    .flip-wrapper {
      width: 300px;
      height: 300px;
      border-radius: 50%;
      .flip-card {
        width: 100%;
        height: 100%;
        background-color: #e1b6ea; /* lavender */
        box-shadow: inset 0 0 30px;
        border-radius: inherit;
      }
    }
    SCSS

    This is what’s currently visible on our screen.

    Creating the CSS flipping card effect animation

    To achieve this captivating effect, we must employ the following two CSS properties: animation and @keyframes. Let’s dive deeper into their analytical exploration.

    To create an infinite flipping card animation it is essential to connect the animation and @keyframes CSS properties. Otherwise, it won’t work.

    Setting the animation CSS property

    In this section of the code, we’re applying the CSS animation property to the element we want to make the animation, in our case to the .flip-wrapper class. The purpose of this property is to associate the animation with the element, as we mentioned above.

    • First of all, we need a name for our animation. Here the animation is named rotation. This name acts as a reference point, allowing us to reuse and target this specific animation throughout our stylesheet.
    • Then we have to give it a duration. Our example has a duration of 8 seconds 8s. This duration defines how long the animation takes to complete one cycle, indicating that the entire animation, from start to finish, will span over 8 seconds.
    • Additionally, it’s set to repeat infinitely. This means that once the animation completes, it restarts immediately and runs continuously without a break. This creates a continuous animation effect (loop 🌪 😂).

    In summary, we are using the animation property to apply an animation named ‘rotation’ to the .flip-wrapper class, making it last for 8 seconds and repeat indefinitely, resulting in an uninterrupted, continuous animation for an element.

    .flip-wrapper {
      ...
      animation: rotation 8s infinite;
      .flip-card {
        ...
      }
    }
    SCSS

    Ways to add the @keyframes

    In the @keyframes rotation section, we define the animation behavior. It specifies a transformation that involves rotating an element around its X-axis and Y-axis. Here’s a breakdown of its key components:

    • @keyframes: This is the rule used to define the keyframes for the animation. Keyframes specify how the animation should change over time, in this case, from the starting state (from) to the ending state (to).
    • rotation: This is the name given to the animation, and it will be used to reference the animation when applying it to elements using the animation property.
    • from and to: These define the initial and final states of the animation. In the from state, the element has a rotation of 0 degrees around the X-axis, meaning it starts with no rotation. In the to state, the element is rotated 360 degrees, completing one full rotation, around the X-axis and/or Y-axis.
    • transform: The transform property is used to apply a specific transformation to the element. In rotation animations, (the specific transformation applied can vary, such as rotating, scaling, or skewing the element.) it enables the element to change its orientation.
    transform: rotateY()

    In the following CSS animation, named rotation , our animation starts from a rotation of 0 degrees (from) and smoothly transitions to a 360-degree rotation (to) around the Y-axis.

    /* ANIMATION */
    @keyframes rotation {
      from {
        transform: rotateY(0deg);
      }
      to {
        transform: rotateY(360deg);
      }
    }
    SCSS
    transform: rotateX()

    This CSS animation, named rotation rotates the element around its X-axis. It starts (from) with no rotation (0 degrees) and smoothly completes (to) a full 360-degree rotation.

    /* ANIMATION */
    @keyframes rotation {
      from {
        transform: rotateX(0deg);
      }
      to {
        transform: rotateX(360deg);
      }
    }
    SCSS

    We have the capability to create rotations along both the Y and X axis at the same time.

    transform: rotateX() rotateY()

    In this CSS animation named rotation the element is rotated in both the X and Y axes. It starts (from) with no rotation (0 degrees in both axes) and gradually complete (to) a full 360-degree rotation in both the X and Y axes. This animation can create a complex spinning effect that involves rotations in multiple directions. Cool huh!! 😎

    /* ANIMATION */
    @keyframes rotation {
      from {
        transform: rotateX(0deg) rotateY(0deg);
      }
      to {
        transform: rotateX(360deg) rotateY(360deg);
      }
    }
    SCSS

    What to avoid when making a CSS flipping card effect animation

    As a reminder, it’s important to ensure that our animation transitions smoothly. To achieve a complete rotation, we must rotate (from) 0 degrees (to) 360 degrees. In the provided animation code, the @keyframes specifies a rotation of (160 deg) for both the X and Y axes, resulting in a card flip effect. However, this setup does not create a smooth transition beyond the 180-degree point. The card abruptly returns to its initial position, giving it a characteristic stop-and-return appearance. To achieve a more natural and realistic flipping effect, we need to ensure a complete 360-degree rotation or a half 180-degree rotation.

    /* ANIMATION */
    @keyframes rotation {
      from {
        transform: rotateX(0deg) rotateY(0deg);
      }
      to {
        transform: rotateX(160deg) rotateY(160deg);
      }
    }
    SCSS

    🌼 Hope you found my post interesting and helpful.
    Thanks for being here! 🌼

  • Static VS Dynamic Design With CSS – From Stillness to Action

    Static VS Dynamic Design With CSS – From Stillness to Action

    CSS in motion! Another perfect title for this post, as CSS is no longer just a language to style static pages, but also to elevate them with animations. CSS entered a new era and has grown into a clever tool that brings digital interfaces to life through movement. It began to shine, showing its full potential and ultimately becoming part of the experience, not just the look.

    CSS properties for movement

    Now, time to focus on where CSS credits its upgrade. Utilizing the following properties: transformtransitionanimation and @keyframes, elements can scaleslidefadespin and move through time all without a single line of JavaScript. Today, we’ll focus on understanding how these properties create such amazing visual feedback. We’ll take a step back from the code and examine these features from a more theoretical perspective: what they mean, how they influence behavior, and why they play such a crucial role in modern design.
    So, let’s zoom in! 🧐

    Transform CSS property

    It applies 2D or 3D transformations 🛠 to an element. It can change the sizerotation, position, and shape.
    Values:

    • scale(): Resize elements – making them smaller or bigger depending on our preferences (use unitless numbers).
    • skew(): Slant elements (use deg, which stands for degrees).
    • translate(): Move elements (use length units like: %pxrem, etc.).
    • rotate(): Spin elements (use deg, like skew).

    📌 Depending on our needs and preferences, we are free to make combinations with the above values.

    • perspective(): Creates a 3D effect, giving the elements a sense of depth.
    • matrix(): Creates 2D transformations. It provides a streamlined approach for applying scaling, skewing, translation, and rotation through a unified matrix. (a mathematical representation – transform: matrix(a, b, c, d, e, f) – that combines the first three transformations into a single matrix. If you want to include rotation as well, you would replace a, b, c, and d with the appropriate cosine and sine values for the desired rotation angle, while keeping e and f for translation.)

    Transition CSS property

    It animates changes in property values over time ⏳ and smoothens the transition between two stages (e.g. on hover, focus)
    Values:

    • transition-property: What property will animate (e.g. transformopacity)
    • transition-duration: How much time does the transition take to complete (e.g. 0.4ss stands for seconds, we are free to use ms too, for milliseconds)
    • transition-timing-function: Define the speed curve (easelinearease-inease-outease-in-out)
    • transition-delay: The time you wait before an animation starts (s and ms, similar to animation-duration). Its default value is 0s, which means the transition will start instantly.

    Keyframes CSS property

    Define intermediate states of an animation 📽 series. Breaks the animation into episodes 🎬, like “first episode, look like this,” “second episode, change to this,” “third episode, change to that,” and “final episode, finish like that.” Each episode represents a point in the timeline where the property-value changes (opacity, rotation, color, etc.).
    Values:

    • From / To : Timeline positions
    • Percentages % : Timeline positions

    📌 Each one represents a property-value pair that defines the appearance at a specific moment

    Animation CSS property

    It runs 🎞 a full animation based on the @keyframes you have defined. Unlike the transition we mentioned above, which moves from one point to another, animations can have many points ⏱ and follow more complex timing rules.
    Values:

    • name: the identifier of the @keyframes rule
    • duration: for how long it moves
    • time-function: how the speed flows
      • ease: it gives a smooth motion, starts slow, continues faster, and ends slow again (which is the default value)
      • linear: it has the same speed all the way
      • ease-in: it starts slow, then it speeds up
      • ease-out: it starts fast, then it slows down (Suitable for hover effects 😎)
      • ease-in-out: starts slow, in the middle spreads up, then slows down again
    • delay: if the animations begin immediately or with a delay
      • a value of 0s (seconds) indicates it starts as soon as it’s applied (which is the default value)
      • positive value that it will start after a set amount of time (e.g. 2s, which means it will start 2 seconds later)
      • negative value that starts straightforward but acts like it has already begun (e.g. -2s the animation won’t wait — it’ll jump in as if it had already been playing for 2 seconds. This can be very helpful if you want animations to be already in motion when the page loads. 😎)
    • iteration-count: how many times to repeat (infinite12, ech)
    • direction: in which direction the animation moves
      • normal ➡ the animation moves forward (which is the default value)
      • reverse ⬅ the animation moves backward
      • alternate ➡ ⬅ first forward, then backward
      • alternate-reverse ➡ ⬅ ➡ first forward, then backward, then again forward
    • fill-mode: shows how the element should look like before the animation starts or after it ends. You have the option to freeze the first or last frame so it doesn’t snap back (➡ forwards, ⬅ backwards). The default value is none, which means it does not apply any styles to the elements.
    • play-state: control if the animation is running or paused, like play ▶ or pause ⏸ buttons (runningpaused)

    📌 For an animation to actually play, we need to utilize only the: animation-nameanimation-duration and the @keyframe. All the other CSS properties are optional.

    When creating content for the web, even the smallest detail can significantly alter how something appears. The experience of bringing elements to life is amazing! It doesn’t need to be dramatic or complex. A simple yet well-structured and strategically placed change at the right moment can make everything more connected, useful and realistic.

    🌼 Hope you found my post interesting and helpful.
    Thanks for being here! 🌼

  • Flipping Card Animation On Hover Using Transform And Transition CSS Properties

    Flipping Card Animation On Hover Using Transform And Transition CSS Properties

    Greetings! Today, I’m excited to walk you through the steps of crafting an amazing CSS flipping card animation that will activate when the user hovers over it. By following my detailed guidance, you’ll learn how to create a stunning animated card that will grab the attention of your viewers and enhance the overall appearance of your website. So, don’t miss out! 😉

    Let’s focus on making this unique animation!

    CSS Flipping card animation on hover

    The provided HTML and SCSS (Sass) code creates a flip card that moves along the Y and X axis. The X-axis and Y-axis are two lines that cross each other. They’re used to define the location of a point in a two-dimensional space.

    Let’s break down the code step by step:

    HTML structure

    To start, let’s focus on the HTML structure. We begin by creating a parent container with the class flip-wrapper. This container serves as the parent for our captivating animation. Inside this wrapper, we have a child element with the .flip-card class. This particular element is where our animation will take place.

    <div class="flip-wrapper">
      <div class="flip-card"></div>
    </div>
    HTML

    CSS basic structure

    In our CSS code snippet, we start by setting the background-color of the entire page to a deep shade of dark blue (#213450).

    Moving on to the .flip-wrapper container, we specify its dimensions, giving it a fixed width and height of 300 pixels. To create a circular or rounded appearance, we apply border-radius. It’s worth noting that, if desired, you can leave the dimensions as is to maintain a square 🟪 shape. I chose this rounded 🟣 design because it makes it easier for us to observe the effect we’re aiming for. 😉

    Next, we focus on the .flip-card element. We set its witdh and height to 100% to ensure it covers the entire available space. We also enhance its visual appeal with a soothing pastel purple (lavender) background-color and a subtle gray shadow effect. To maintain the circular theme, we add the inherit value to border-radius property.

    body {
      background-color: #213450; /* dark blue */
    }
    
    .flip-wrapper {
      width: 300px;
      height: 300px;
      border-radius: 50%;
      .flip-card {
        width: 100%;
        height: 100%;
        background-color: #e1b6ea; /* lavender */
        box-shadow: inset 0 0 30px;
        border-radius: inherit;
      }
    }
    SCSS

    This is what’s visible on our screen at the moment.

    Ways to add the hover effect

    For our effect to function as intended we have to work with both the parent and the child element. We begin with the parent element where we apply the :hover effect and change the cursor to a pointer 👆. You can check out all cursor style and pick the one that suits you best. 🤗

    .flip-wrapper {
      ...
      &:hover {
        cursor: pointer;
      }
    }
    SCSS

    Next, we’ll move on to our child element. Here, we set the transform CSS property to rotateY and specify the degree (deg) of rotation we desire.

    Afterward, we’ll define the transition CSS property. We can use it in two ways. We add it to the :hover or we can add it directly to the .flip-card class. In the first case, the effect works only when you hover in. In the second case, the effect works when you hover in, but when you hover out it turns back to its original position. Then we set the transform value and specify the duration in seconds (s). In our case, I’ve chosen 8 seconds to make the effect slow and easily observable. 😉

    transform: rotateY()

    hover-in
    .flip-wrapper {
      ...
      &:hover {
        ...
        .flip-card {
          ...
          transform: rotateY(180deg);
          transition: transform 8s;
        }
      }
    }
    SCSS
    hover-in-out
    .flip-wrapper {
      ...
      &:hover {
        ...
          transform: rotateY(180deg);
        }
        .flip-card {
          transition: transform 8s;
        }
      }
    }
    SCSS

    transform: rotateX()

    We do the same, but this time along axisX.

    hover-in
    .flip-wrapper {
      ...
      &:hover {
        ...
        .flip-card {
          ...
          transform: rotateX(360deg);
          transition: transform 8s;
        }
      }
    }
    SCSS
    hover-in-out
    .flip-wrapper {
      ...
      &:hover {
        ...
          transform: rotateX(360deg);
        }
        .flip-card {
          transition: transform 8s;
        }
      }
    }
    SCSS

    We have the capability to create rotations along both the Y and X axes at the same time.

    transform: rotateX() rotateY()

    hover-in
    .flip-wrapper {
      ...
      &:hover {
        ...
        .flip-card {
          ...
          transform: rotateX(180deg) rotateY(180deg);
          transition: transform 8s;
        }
      }
    }
    SCSS
    hover-in-out
    .flip-wrapper {
      ...
      &:hover {
        ...
          transform: rotateX(180deg) rotateY(180deg);
        }
        .flip-card {
          transition: transform 8s;
        }
      }
    }
    SCSS

    🌼 Hope you found my post interesting and helpful.
    Thanks for being here! 🌼

  • How To Build Stunning Rounded Text – Handy Tips

    How To Build Stunning Rounded Text – Handy Tips

    Greetings, all! 😃 I’m excited to share an incredible CSS technique with you today. We’ll learn little by little how to create impressive and rounded text. This technique can give our text a unique and captivating appearance that stands out from the usual. Get ready to take your text to the next level! 🧨 ⚡

    Are you interested in learning how to uplevel your typography? Stick around to explore the endless possibilities of CSS and take your website to new heights! Let the game 🌀 begin and happy designing! 😊

    HTML structure

    To create a text that appears in a rounded effect we begin with the HTML structure. First, we need an HTML div with a specific class. Let’s call it .wrapper. This div will be the container where the text will be displayed. To achieve the desired effect, we also need to add a span element for each character we want to use. By doing so, it allows us to handle and move each character separately and create the shape we want. 😉

    In our example, we will use 15 letters and a star, so we need to add 16 spans. Each span represents a character. You can see the code snippet below for a better understanding.

    <div class="wrapper">
      <span class="character1">I</span>
      <span class="character2">a</span>
      <span class="character3">m</span>
      <span class="character4">a</span>
      <span class="character5">r</span>
      <span class="character6">o</span>
      <span class="character7">u</span>
      <span class="character8">n</span>
      <span class="character9">d</span>
      <span class="character10">e</span>
      <span class="character11">d</span>
      <span class="character12">t</span>
      <span class="character13">e</span>
      <span class="character14">x</span>
      <span class="character15">t</span>
      <span class="character16-emoticon"></span>
    </div>
    HTML

    CSS structure

    We move forward with the CSS. We begin by styling the wrapper HTML element with a width and height of 400 pixels. It will also have a purple background-color, an inset magenta shadow (the inset box-shadow is a clever idea 💡 to create a distinctive boundary inside our wrapper, which will help us later with the positioning), and a border-radius of 50%, giving it a completely round shape. Finally, the flex method will perfectly align our text inside the wrapper.

    Next, we will apply some styling to the spans within the wrapper. They will have a font-family: Arial (we need a really distinct font), a font-size of 40 pixels, and will be colored in a yellowish shade (#eddc42).

    🔖 Note that we won’t add spaces between characters since we will place them one by one. By avoiding spaces, we can achieve precise and accurate positioning, which allows for greater control and flexibility in our design.

    .wrapper {
      width: 400px;
      height: 400px;
      background-color: purple;
      box-shadow: inset 0 0 0px 60px magenta;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
     span {
      font-family: Arial;
      font-size: 40px;
      color: #eddc42;
    }
    CSS

    Below, we can see what is generated on the screen for now. Well, 🤔 in fact, I’m not a rounded text yet! 😃 So, let’s move on!

    Preparation before starting to position the letters

    To be able to make the positioning, we set position: relative property to the wrapper and position: absolute property to the span as a way to move them freely. By doing so, all characters take the same place, but we can observe only the last one as it is on the top.

    .wrapper {
      position: relative;
    }
    
     span {
      position: absolute;
    }
    CSS

    Now, we can see what is currently shown on the screen.
    While I’m not a looping message so far, 🤪 I will be soon! Let’s proceed. 😃

    Creating the rounded shape

    Starting from the two ends and going toward the middle side is a smart tactic to divide the space equally. Remember, we have a star that we will put in the center of the circle, so we do not count it. Thus, we initiate our positioning from the letters “Ι and t”, the first and last letter of our phrase, and place them in the middle of axis-Y by setting top: 50% and transform: translate(-50%) .

    Also, we keep the letters 40 pixels away from the left and right sides, with the left and right CSS properties respectively.

    Finally, transforming our letters setting the transform: rotate() gives them a vibrant and dynamic perspective, bringing them to life in a truly inspiring way.

    .character1 {
      left: 40px;
      top: 50%;
      transform: translate(0, -50%) rotate(-90deg);
    }
    
    .character15 {
      right: 40px;
      top: 50%;
      transform: translate(0, -50%) rotate(90deg);
    }
    CSS

    Now, take a look at this sequence of characters. Notice how both the first and last letters are in their respective positions on the displayed screen. This is a good time to examine how the box-shadow CSS property helps us to count and place the characters accurately. 🟣 🤩 🟣 🤩 🟣

    We move forward with this topic by counting the remaining characters. Ι know! I know! It can be a bit tricky and confusing 🤯 because of the counting, but the result will be amazing!! ✨ 🎉 Therefore, please ensure to maintain the positioning using the same tactic consistently. Finally, I’m including the rest of the code snippet below to complete my work.

    .character2 {
        transform: rotate(-75deg);
        left: 38px;
        top: 144px;
      }
      
      .character3 {
        transform: rotate(-65deg);
        left: 42px;
        top: 113px;
      }
    
      .character4 {
        transform: rotate(-45deg);
        left: 80px;
        top: 68px;
      }
      
      .character5 {
        transform: rotate(-32deg);
        left: 120px;
        top: 42px;
      }
      
      .character6 {
        transform: rotate(-20deg);
        left: 140px;
        top: 32px;
      }
      
      .character7 {
        transform: rotate(-10deg);
        right: 208px;
        top: 25px;
      }
      
      .character8 {
        transform: rotate(5deg);
        right: 175px;
        top: 24px;
      }
      
      .character9 {
        transform: rotate(22deg);
        right: 145px;
        top: 30px;
      }
      
      .character10 {
        transform: rotate(30deg);
        right: 118px;
        top: 42px;
      }
      
      .character11 {
        transform: rotate(42deg);
        right: 90px;
        top: 60px;
      }
      
      .character12 {
        transform: rotate(65deg);
        right: 60px;
        top: 100px;
      }
      
      .character13 {
        transform: rotate(65deg);
        right: 45px;
        top: 122px;
      }
      
      .character14 {
        transform: rotate(80deg);
        right: 38px;
        top: 152px;
      }
    CSS

    As we can see, all letters are in their respective positions on the displayed screen and our text is finally taking a rounded shape. 🟣 🤩 🟣 🤩 🟣

    To finalize, it would be better if the star appears bigger so we modify the .character16-emoticon class and adjust the font-size property to 100px. Additionally, the box-shadow property needs to be updated to achieve the desired visual effect. Therefore, we will need to go back and make the necessary changes to ensure it looks exactly as we want it to.

    .wrapper {
      ...
      box-shadow: inset 0 0 30px 10px magenta;
    }
    
    .character16-emoticon {
      font-size: 100px;
    }
    CSS

    Tada! Our rounded text is ready! 🥳 💪 Enjoy! 🎊 🎊

    Complete code solution

    Below is the full code referenced in this blog post. Feel free to copy and use it in your own projects. If you have any questions or encounter any issues, don’t hesitate to reach out for assistance. You can easily copy the desired code snippet by clicking on the copy icon, located in the top-right corner of each snippet.

    <div class="wrapper">
      <span class="character1">I</span>
      <span class="character2">a</span>
      <span class="character3">m</span>
      <span class="character4">a</span>
      <span class="character5">r</span>
      <span class="character6">o</span>
      <span class="character7">u</span>
      <span class="character8">n</span>
      <span class="character9">d</span>
      <span class="character10">e</span>
      <span class="character11">d</span>
      <span class="character12">t</span>
      <span class="character13">e</span>
      <span class="character14">x</span>
      <span class="character15">t</span>
      <span class="character16-emoticon"></span>
    </div>
    HTML
    Expand
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    html,
    body {
      height: 100vh;
    }
    
    body {
      background-color: #f5f5f5;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
    .wrapper {
      width: 400px;
      height: 400px;
      background-color: purple;
      box-shadow: inset 0 0 0px 60px magenta;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
     span {
      font-family: Arial;
      font-size: 40px;
      color: #eddc42;
    }
    
    .character1 {
      left: 40px;
      top: 50%;
      transform: translate(0, -50%) rotate(-90deg);
    }
      
    .character2 {
      transform: rotate(-75deg);
      left: 38px;
      top: 144px;
    }
      
    .character3 {
      transform: rotate(-65deg);
      left: 42px;
      top: 113px;
    }
    
    .character4 {
      transform: rotate(-45deg);
      left: 80px;
      top: 68px;
    }
      
    .character5 {
      transform: rotate(-32deg);
      left: 120px;
      top: 42px;
    }
      
    .character6 {
      transform: rotate(-20deg);
      left: 140px;
      top: 32px;
    }
      
    .character7 {
      transform: rotate(-10deg);
      right: 208px;
      top: 25px;
    }
      
    .character8 {
      transform: rotate(5deg);
      right: 175px;
      top: 24px;
    }
      
    .character9 {
      transform: rotate(22deg);
      right: 145px;
      top: 30px;
    }
      
    .character10 {
      transform: rotate(30deg);
      right: 118px;
      top: 42px;
    }
      
    .character11 {
      transform: rotate(42deg);
      right: 90px;
      top: 60px;
    }
      
    .character12 {
      transform: rotate(65deg);
      right: 60px;
      top: 100px;
    }
      
    .character13 {
      transform: rotate(65deg);
      right: 45px;
      top: 122px;
    }
      
    .character14 {
      transform: rotate(80deg);
      right: 38px;
      top: 152px;
    }
    
    .character15 {
      right: 40px;
      top: 50%;
      transform: translate(0, -50%) rotate(90deg);
    }
    
    .character16-emoticon {
      font-size: 100px;
    }
    
    CSS
    Expand

    🌼 Hope you found my post interesting and helpful.
    Thanks for being here! 🌼

  • How CSS Became So Powerful with Animations

    How CSS Became So Powerful with Animations

    Hi there! You’re aware that the web 🕸 wasn’t always like it is today? Websites were like digital 📰 posters – just text and images. A page loads, and no changes occur. Static design had the reins. No movement, no glow! 🤹‍♀️ ✨ Everything remained visually frozen. 🧊 🥶 CSS was only a tool to decorate that static content and make some improvements, such as selecting a font, changing colors, adding a border or a margin.

    As time went on, browsers improved, and users began to expect more. That’s when CSS started to shine and show the way from static pages to fluid experiences! With features like transition, transform, animation, and keyframes, the focus shifted from how things looked to how they can pulse and move in time. Dynamic design is finally here! CSS became a language capable of transforming static HTML elements into dynamic 🧨 ones.

    Motion matters. It allows users to feel when something changes and witness how elements react. It’s a way of communication, 🔊 not just decoration. With only CSS, designers can craft these interactions. Creating animations that ‘rotate‘, ‘skew‘, scale‘ or ‘shift‘ position suggests ongoing system activity. A sliding menu, like a ‘hamburger icon‘, reveals categories, indicating that navigation continues beyond the current view. A spinning icon, after a user clicks ‘Submit’ or ‘Save’ on a button, signals that a process is loading. A button that gently fades in and out on hover – labeled ‘Sign Up‘ – asks for interaction. A fading alert, such as ‘Connection lost‘ or ‘Download has failed, retrying‘, quietly suggests that the message is temporary. Even a ‘scale-up‘ focusing on an image can reveal that it is active. CSS became a must to represent progress and maintain users’ attention.

    Of course, as with everything, setting boundaries is essential. Many times action can cause confusion and make users feel distracted or, even worse, rushed. Not every interface needs to include movement. Sometimes, picking stillness is the best choice. Valuable designs recognise when to pause!

  • Make a Unique Folded Corner Effect Utilizing the clip-path CSS Property

    Make a Unique Folded Corner Effect Utilizing the clip-path CSS Property

    Hello everybody! I’m excited to share a cool folded corner effect I created using just HTML and CSS. This eye-catching design adds a dynamic flair, creating a realistic illusion that enhances your webpage’s visual appeal —no images, extra scripts, or complex code required. How awesome is that? 😎

    Elements with clip-path do not take shadows directly. Instead, they must be nested within a container to inherit its shadows.

    Creating the folded corner effect using pseudo-element

    We’ll start by using the :before pseudo-element combined with the clip-path property to create the folded corner effect. The main element, which contains the pseudo-element, is styled with a filter property to apply a shadow. This shadow is then inherited by the pseudo-element, allowing the folded corner to display a subtle, realistic shadow as well. This technique keeps the design lightweight and visually appealing.

    Basic HTML structure for the folded corner effect

    The HTML code snippet creates a card layout. We have a parent element with the class .card, housing two child elements: the first with the class .title for the card’s title, and the second with the class .folded-corner to apply the folded corner effect via CSS.

    <div class="card">
      <div class="title">Folded Corner Effect</div>
      <div class="folded-corner"></div>
    </div>
    HTML

    CSS structure: creating the paper and cut corner

    Starting with the CSS, we define a horizontal rectangle by setting the width to 450px and the height to 300px, along with a subtle 2px border-radius for slightly rounded corners. The background color is set to #228a90, a rich teal with greenish-blue tones that gives the card a fresh, modern look.

    .card {
      width: 450px;
      height: 300px;
      border-radius: 2px;
      background-color: #228a90;
        
      display: flex;
      align-items: center;
      justify-content: center;
    }
    CSS
    Initial paper design before applying folded corner effect

    Then we use the clip-path property to shape the desired paper corner for the folded effect. I chose the top-left corner, but you can select any one you prefer by adjusting the corresponding points in the clip-path: polygon() function.

    .card {
      width: 450px;
      height: 300px;
      border-radius: 2px;
      background-color: #228a90;
      
      clip-path: polygon(0% 30%, 30% 0%, 100% 0%, 100% 100%, 0% 100%);
      position: relative;
    }
    CSS

    Think of the corners in this order: top-left, top-right, bottom-right, bottom-left (clockwise).

    Remember to split each selected corner into two coordinates to get the right look (watch those 👇 magenta measurements! 😉)
    Take into account that the top-left corner has both Axis-X and Axis-Y on 0%.

    Axis coordinates of card showing top-left corner cut, preparing the folded corner effect

    Finally, adding position:relative does not change something in our effect but prepares us for future positioning adjustments. As for centering our elements using flexbox—it’s purely for aesthetic purposes, helping keep everything visually balanced and neat.
    Below, we can see what is rendered on the screen for now. Pretty cool, right!? 😃

    Progress so far: paper with cut corner created using HTML and CSS folded corner effect

    CSS structure: how to create the folded corner effect

    To continue building our effect, we’ll use the folder-corner child element to create a second rectangle within the parent card element. This element will act as the folded piece of paper. We’ll give it a width of 70px and a height of 160px.

    .card .folded-corner {
      width: 70px;
      height: 160px;
      background-color: red;
      position: absolute;
    }
    CSS

    For now, we’ll use a red background color to help us visualize its position and behavior more clearly—this will be updated to its final color later. We’ll also apply position: absolute to enable precise positioning.

    Initial red-colored container element for folded corner effect

    Next, we continue with positioning. We use the top and left properties to move the .folded-corner element closer to the clipped corner, then apply the transform property to rotate it into place.

    .card .folded-corner {
      ...
      top: -7px;
      left: 52px;
      transform: rotate(56deg);
    }
    CSS
    Positioning folded-corner element at top -7px in folded corner effect layout
    top: -7px;
    Positioning folded-corner element at left 52px to align with cut corner
    left: 52px;
    Rotating folded-corner element by 52 degrees using CSS transform property
    transform: rotate(56deg);

    Finally, adding the filter property is essential for completing our effect. As mentioned earlier, applying a shadow directly to an element with a clip-path isn’t possible — so the solution is to create an additional element that can hold the shadow.

    To do this, we’ll add a :before pseudo-element with the same dimensions as our folded corner. This allows us to recreate the folded shape and apply the shadow to it — adding depth and realism to the folded corner effect. 😎

    .card .folded-corner {
      ...
      top: -7px;
      left: 52px;
      transform: rotate(56deg);
      filter: drop-shadow(6px 4px 5px rgba(0, 0, 0, 0.4));
    }
    CSS
    Initial red-colored container element for folded corner effect
    filter: drop-shadow(6px 4px 5px rgba(0, 0, 0, 0.4));

    Next, we move forward by using the before pseudo-element with the content property and set its position to absolute for precise placement within the parent.
    We want this pseudo-element to have the exact dimensions as the parent, so we set both its width and height to 100%, something that allows it to inherit the parent’s size.

    .card .folded-corner:before {
      content: "";
      position: absolute;
      width: 100%;
      height: 100%;
      background: pink;
      border-radius: 0 0 10% 0;
    }
    CSS

    For now, we apply a pink background to help visualize the structure. Finally, we add a border-radius of 10% to the bottom corner, which softens the edge and creates a smoother, more realistic folded appearance.

    Adding the before pseudoelement

    Next, we replace the pink background with a smooth linear gradient. We choose colors similar to the main hue but make them darker towards the edges and lighter in the center. This gradient effect enhances the appearance by making the center appear brighter and polish. ✨

    .card .folded-corner:before {
      ...
      background: linear-gradient(to right, #277c7f 5%, #5abcbc 30%, #63c5c6 40%, #5abcbc 50%, #277c7f 90%, #0d4749);
    }
    CSS
    Adding linear- gradient at the before pseudoelement

    To complete the shape, we apply the clip-path: polygon(0% -2%, 0% 100%, 100% 100%) property. This is essential for transforming the before pseudo-element —which starts as a rectangle, just like its parent—into a triangle.

    In simple words, this clipping path reshapes the element into the desired triangular form. 🥳

    .card .folded-corner:before {
      ...
      clip-path: polygon(0% -2%, 0% 100%, 100% 100%);
    }
    CSS
    Adding clip-path to the before pseudoelement

    The last step is to turn back to the parent element with the class .folded-corner and “remove” the red rectangle from view by simply replacing the red background-color with a transparent value.
    As we can see, the :before pseudoelement inherits its parent shadow effect while the parent becomes invisible.

    .card .folded-corner {
      width: 70px;
      height: 160px;
      background-color: transparent;
      position: absolute;
      top: -7px;
      left: 52px;
      transform: rotate(56deg);
      filter: drop-shadow(6px 4px 5px rgba(0, 0, 0, 0.4));
    }
    CSS
    Finalize the folded corner effect

    We can enhance the title to have a more eye-cathing result. Applying a white background-color, increasing the font-size, and adding a subtle black text-shadow will make the title stand out beautifully, elevating the overall design. 📄 ✨

    .card .title {
      font-family: sans-serif;
      font-size: 40px;
      font-weight: bold;
      text-align: center;
      padding: 0 50px;
      color: white;
      text-shadow: 1px 1px 1px black;
    }
    CSS
    Stylling paper's title

    Complete code example

    <div class="card">
      <div class="title">Folded Corner Effect</div>
      <div class="folded-corner"></div>
    </div>
    HTML
    .card {
      width: 450px;
      height: 300px;
      border-radius: 2px;
      background-color: #228a90;
      clip-path: polygon(0% 30%, 30% 0%, 100% 0%, 100% 100%, 0% 100%);
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
    .card .folded-corner {
      width: 70px;
      height: 160px;
      background-color: transparent;
      position: absolute;
      top: -7px;
      left: 52px;
      transform: rotate(56deg);
      filter: drop-shadow(6px 4px 5px rgba(0, 0, 0, 0.4));
    }
    
    .card .folded-corner:before {
      content: "";
      position: absolute;
      width: 100%;
      height: 100%;
      border-radius: 0 0 10% 0;
      background: linear-gradient(to right, #277c7f 5%, #5abcbc 30%, #63c5c6 40%, #5abcbc 50%, #277c7f 90%, #0d4749);
      clip-path: polygon(0% -2%, 0% 100%, 100% 100%);
    }
    
    .card .title {
      font-family: sans-serif;
      font-size: 40px;
      font-weight: bold;
      text-align: center;
      padding: 0 50px;
      color: white;
      text-shadow: 1px 1px 1px black;
    }
    CSS
    Expand

    If you have any questions or run into any issues, don’t hesitate to reach out in the comments below — I’m happy to help. You can easily copy any code snippet by clicking the copy icon in the top-right corner of each block.

    Summary

    We started by creating the paper and cutting its corner. Then, we set the clip-path property to define the shape and positioned the folded-corner element precisely over the clipped area. After that, we enhanced the styling with background gradients that match the paper’s tone, and wrapped up by polishing the effect for a clean, realistic look. 📄 ✨

    Wishing you the best of luck in all your creative endeavors! 😃

  • Keyframes in CSS Explained – Make Your Animations Stand Out

    Keyframes in CSS Explained – Make Your Animations Stand Out

    Hi there! 😃 In today’s post, we will analyze the amazing CSS @keyframes rule, an incredibly powerful tool for creating complex and visually stunning animations on web pages.

    Understanding keyframes in CSS

    In simple terms, keyframes define the animation’s behavior through a series of @keyframes which describes how the animation should change over time.
    Each keyframe represents a specific point in time, and CSS smoothly transitions between these keyframes to create fluid motion.

    With CSS keyframes, you can create various animations, from simple color changes to complex effects like movements and transformations. By combining keyframes with other CSS properties, we can control timing and duration and create dynamic and visually engaging websites.

    I will provide you with an example that will make this at-rule crystal clear. 🧐 Let’s grab a ☕ and move forward. 🚀 We’ve got this!

    Example of keyframes in CSS: The theory behind it

    The details of the animation will depend on the specific effect we want to achieve. Let’s say we want to create an animation where a square ⬛ transforms into a circle ⚫ and then back into a square ⬛ again. Additionally, the color 🌈 of the shape changes during the animation, and there are some movements and transitions involved. It might seem massive and confusing, 😰 but we can deal with it step by step together! 🛠

    For our animation to be smooth and realistic, we need to define the @keyframes. The first keyframe serves as the starting point (0%), followed by intermediate points and the final keyframe (100%) that marks the end of the animation and returns to the starting point.

    😃The following code snippet provides a quick example of a keyframes structure in action.

    @keyframes name-of-keyframe {
      0% {
        ... /* this is the starting point */
      }
      50% {
        ... /* this is one intermediate point */
      }
      100% {
        ... /* this is the ending point */
      }
    }
    CSS

    To create these keyframes, you’ll need to use CSS animation properties, such as animation-name, animation-duration, animation-iteration-count and animation-delay. The animation-name property connects the animation to its keyframes, while the other properties control how long it should last, how it should behave over time, and whether it has a delay before starting..

    Once you’ve defined your keyframes and animation properties, CSS will automatically insert transitions between the keyframes to create smooth changes. This means you don’t need to worry about manual calculations. CSS takes care of it for you. Cool huh!? 😎 ✨

    Example of keyframes in CSS: Practical implementation

    As we already mentioned, we will work with a box. We need to start with the HTML code and create a <div> element that has the class name .box.

    <div class="box"></div>
    HTML

    Then, in our CSS code, we define the basic properties. It should be a square with a width and height of 200 pixels, and we’ll keep the background-color simple by using black for now.

    .box {
      width: 200px;
      height: 200px;
      background-color: black;
    }
    CSS

    This is what is rendered on the screen for now. A simple black box.

    Applying animation effects to the elements

    To add animation effects to our <div> element, we need to define the animation properties of our class .box. We set the animation-name, which is the animation’s name, then the animation-duration, which is the time the animation takes to complete, and finally, the animation-iteration-count which declares how many times the animation should repeat.

    .box {
      ...
      animation-name: my-animation;
      animation-duration: 10s;
      animation-iteration-count: infinite;
    }
    
    /* ----- MY ANIMATION ----- */
    @keyframes my-animation {}
    CSS

    Then, we create our animation using the @keyframes rule, where we can specify the values of the CSS properties at different points during the animation. The most crucial step is to link the animation to our element. We do this by using the animation-name property and assigning it to the same name we defined earlier. In our case my-animation.

    Transforming colors and shapes with animation

    We will start our transformations by working with colors and shapes using the background-color and border-radius properties.

    /* ----- MY ANIMATION ----- */
    @keyframes my-animation {
      0% {
        background-color: pink;
      }
      25% {
        background-color: purple;
        border-radius: 50%;
      }
      50% {
        background-color: black;
        border-radius: 50%;
      }
      75% {
        background-color: purple;
        border-radius: 50%;
      }
      100% {
        background-color: pink;
      }
    }
    CSS

    As we can see, it begins with a pink square at starting point: 0%. Then, it transitions to purple (25%) where it starts becoming cyclic. After that, it turns to black (50%) and remains a full circle. Then (75%) shifts to purple again, where it starts transitioning back to a square. Finally (ending point: 100%) turns to a pink square.

    Keyframes in CSS: A pink square transitions into a purple circle, then a black circle, and back to a pink square using CSS @keyframes, background-color, and border-radius properties.

    Animating Element Position

    The next step is adjusting the position of our box. To do this, we need to adjust the positioning of the HTML element associated with our .box class and set it to position: relative, allowing it to move within its container.

    Now, let’s animate its movement:

    • The animation starts at the top-left corner 0%.
    • At 25%, it moves diagonally by changing both the top and left values.
    • At 50%, it continues moving horizontally to the left.
    • At 75%, it moves diagonally back by adjusting top and left again.
    • Finally, at 100%, it returns to its original position at the top-left corner.
    .box {
      ...
      position: relative;
    }
    
    /* ----- MY ANIMATION ----- */
    @keyframes my-animation {
      0% {
        ...
        left: 0px;
        top: 0px;
      }
      25% {
        ...
        left: 200px;
        top: 100px;
      }
      50% {
        ...
        left: 300px;
      }
      75% {
        ...
        left: 200px;
        top: 100px;
      }
      100% {
        ...
        left: 0px;
        top: 0px;
      }
    }
    CSS
    CSS animations: A pink square moves from the top left while transforming into a purple circle, then shifts left and becomes a black circle, before returning to the top left as a pink square using CSS @keyframes, top, and left properties.

    Animating Element Rotation

    We can also make our box a little bit playful! 🤹‍♀️ We will add some extra moves with the amazing transform CSS property.

    We will apply a rotation only between 25% and 75%.

    • The animation starts with no rotation at 0%.
    • At 25%, the element remains unrotated with transform: rotateY(0deg).
    • At 50%, it completes a full rotation with transform: rotateY(360deg)
    • At 75%, it returns to its original position with transform: rotateY(0deg).
    • Finally, at 100%, the cycle resets, ready to repeat.
    /* ----- MY ANIMATION ----- */
    @keyframes my-animation {
      0% {
        ...
      }
      25% {
        ...
        transform: rotateY(0deg);
      }
      50% {
        ...
        transform: rotateY(360deg);
      }
      75% {
        ...
        transform: rotateY(0deg);
      }
      100% {
        ...
      }
    }
    CSS
    CSS animations with @keyframes: This image shows a pink square moving from top left and turning to a purple circle, then moving only to left by rotating at axis-Y and turning to a black circle and then again moving back to top left and turning to a pink square using the CSS @keyframes property and the css transform: rotateY() property.

    Now, let’s try to make it even more impressive by enriching the starting and ending phases.

    • At 0%, we add transform: rotateX(360deg).
    • At 25%, it resets with transform: rotateX(0deg), creating a rotation along the X-axis from 0% to 25%.
    • At 50% and 75%, we maintain a non-rotating phase with transform: rotateX(0deg).
    • Finally, at 100%, we add transform: rotateX(360deg), creating another rotation from 75% to 100%.
    /* ----- MY ANIMATION ----- */
    @keyframes my-animation {
      0% {
        ...
        transform: rotateX(360deg);
      }
      25% {
        ...
        transform: rotateX(0deg);
      }
      50% {
        ...
        transform: rotateX(0deg);
      }
      75% {
        ...
        transform: rotateX(0deg);
      }
      100% {
        ...
        transform: rotateX(360deg);
      }
    }
    CSS
    CSS Keyframes: This image shows a pink square that rotating to axis-X from top left and turning to a purple circle, then moving only to left by rotating at axis-Y and turning to a black circle and then again rotating to axis-X going back to top left and turning to a pink square using the CSS @keyframes property and the css transform: rotateY() property.

    Inserting content into the animated element

    We can also add any content we want (text, image, emoticon, etc.) inside our HTML element. For our example, I use an emoticon and set its font-size to 100px.

    <div class="box">
      <div class="emoticon">🪐</div>
    </div>
    HTML
    .box .emoticon {
      font-size: 100px;
    }
    CSS
    CSS keyframes: This image shows a pink square with a perfectrly centered emoticon (Ringed planet) inside it, that rotating to axis-X from top left and turning to a purple circle, then moving only to left by rotating at axis-Y and turning to a black circle and then again rotating to axis-X going back to top left and turning to a pink square using the CSS @keyframes property. We create this animation setting the CSS animation-name, CSS animation-duration and CSS animation-iteration-count properties.

    Delaying the animation start

    We can add a delay to our animation by setting the animation-delay CSS property. This delay momentarily pauses the animation before it begins, creating a smoother and more controlled start.

    For instance, if we set the delay to 2s, the animation will start after 2 seconds. However, please note that this delay occurs only once when we first see the animation. To observe the effect again, we may need to refresh the page. 

    .box {
      ...
      animation-delay: 2s;
    }
    CSS

    You can see the animation with the delay effect below. It starts with its initial black background-color and after the 2s it starts the transitions we created with the @keyframes. 😉

    CSS Keyframes: This image shows a pink square with a perfectrly centered emoticon (Ringed planet) inside it, that rotating to axis-X from top left and turning to a purple circle, then moving only to left by rotating at axis-Y and turning to a black circle and then again rotating to axis-X going back to top left and turning to a pink square using the CSS @keyframes property. This animation has a starting delay of 2 seconds. We do so using the CSS animation-delay property.

    Using the @keyframes shorthand for animations

    By using shorthand, you can save space and time while improving your code’s readability. Instead of writing multiple properties separately, you can define them all using just the animation shorthand.

    .box {
      animation-name: my-animation;
      animation-duration: 10s;
      animation-iteration-count: infinite;
      animation-delay: 2s;
      
      /* Here’s the shorthand version */
      animation: my-animation 10s 2s infinite;
    }
    CSS

    Complete CSS animation code (copy & paste ready)

    Below is the full code referenced in this blog post. Feel free to copy and use it in your own projects.

    If you have any questions or encounter any issues, don’t hesitate to ask for help. You can easily copy the desired code snippet by clicking on the copy icon, located in the top-right corner of each snippet.

    We’d love to hear your thoughts! If you have feedback or questions, drop a comment below.

    <div class="box">
      <div class="emoticon">🪐</div>
    </div>
    HTML
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    html,
    body {
      height: 100vh;
    }
    
    .box {
      width: 200px;
      height: 200px;
      background-color: black;
      
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      
      animation: my-animation 10s 2s infinite;
    }
    
    .box .emoticon {
      font-size: 100px;
    }
    
    /* ----- MY ANIMATION ----- */
    @keyframes my-animation {
      0% {
        left: 0px;
        top: 0px;
        background-color: pink;
        transform: rotateX(360deg);
      }
      25% {
        left: 200px;
        top: 100px;
        background-color: purple;
        border-radius: 50%;
        transform: rotateY(0deg) rotateX(0deg);
      }
      50% {
        left: 300px;
        background-color: black;
        border-radius: 50%;
        transform: rotateY(360deg) rotateX(0deg);
        visibility: visible;
      }
      75% {
        left: 200px;
        top: 100px;
        background-color: purple;
        border-radius: 50%;
        transform: rotateY(0deg) rotateX(0deg);
      }
      100% {
        left: 0px;
        top: 0px;
        background-color: pink;
        transform: rotateX(360deg);
      }
    }
    CSS
  • How To Make A CSS Text Reflection Effect

    How To Make A CSS Text Reflection Effect

    Hi there! 😃 In this post, we’ll learn bit by bit how to create a CSS text reflection effect. When we say reflection, we’re referring to a mirror-like effect that looks like the text reflects on a surface, much like the way we see our reflection in a mirror.

    This is a simple yet amazing way to enhance the appearance of your text. Let’s analyze our effect so that you can easily follow along.

    HTML structure

    We will begin with our HTML structure. As you can see below, I prepared a div with the class .reflection-text , this is where our effect will take place.

    <div class="reflection-text">HELLO WORLD</div>
    CSS

    CSS foundation

    Let’s move forward with the CSS basic structure. We start with defining the background. It’s worth noting that using radial-gradient can make our effect more impressive. 😃

    body {
      background: radial-gradient(lightgreen, darkgreen);
      height: 100vh;
    }
    CSS

    Below, we can see the background we just created.

    In web development, we use the flex method in order to center our text. Then we will enhance its appearance, by making some adjustments. We will set the font-size to 100 pixels, select the “Roboto” font-family, and choose white as the text color.

    body {
      ...
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
    .reflection-text {
      font-size: 100px;
      font-family: 'Roboto', sans-serif;
      color: white;
    }
    CSS

    This is what is rendered on the screen for now. A perfectly centered, 🎯 white text.

    Adding the CSS structure for the reflection effect

    Creating a reflection can be achieved by using pseudoelements like :before and :after. To ensure this works properly, we need to include position: relative in our .reflection-text class.

    .reflection-text {
      ...
      position: relative;
    }
    CSS

    Now, we are ready to proceed and create our reflection by adding the :before pseudoelement with all the necessary properties, as shown in the following code snippet.

    .reflection-text:before {
      content: "HELLO WORLD";
      position: absolute;
      top: 65px;
      transform: rotate(180deg) scaleX(-1);
      background: linear-gradient(
        to bottom, 
        rgba(255, 255, 255, 0) 20%, 
        rgba(255, 255, 255, 0.5) 60%, 
        rgba(255, 255, 255, 2) 100%
      );
      background-clip: text;
      color: transparent;
      opacity: 0.3;
    }
    CSS

    Breaking down the process

    🟢 To begin, we add the text “HELLO WORLD” to create another text element with the same content. This new text will serve as our reflection. Then, we set position: absolute so that we can move our reflected text below the original text. We use the top property to move the reflected text 65 pixels from the top, but you can always move the reflection in any direction you prefer. It is important to position the text and its reflection closely together for a more realistic reflection effect. 😉

    🟢 We move forward and use the transform CSS property to rotate the text by 180 degrees

    and then flip it horizontally using scaleX(-1). Now we have the perfect reflection! Let’s continue and make it more realistic.

    🟢 In the next step, we will adjust the color of our reflected text. To achieve this, we will utilize the linear-gradient CSS property and specify the direction as downwards. This will create white gradients, with the top appearing more intense and gradually fading towards the bottom of the text.

    🟢 It is commonly known that gradients cannot be directly applied to texts. Don’t worry! 🤔 We already have the solution to this problem. For now, let’s give a quick explanation. To create a clipped linear background pattern for text, first, we add the -webkit-background-clip: text property, and at the same time, we set the color to transparent, and our text automatically turns to transparent. In that way, our text takes the background: linear-gradient as its real color.

    🟢 For a more transparent text, we can adjust the opacity. The lower the opacity, the more transparent our text becomes. So, here we are! Our reflection is ready! 🥳

    Exploring different colors

    🔖 It is always an option to use black or any other color in our work. Below, I’ve included examples of texts with black, purple, and green colors. It’s important to remember that the key factor is to set the correct gradients at the linear-gradient property. That way, we can create respective shades. Therefore, please give extra attention to that! 😊

    Black text

    .reflection-text {
      position: relative;
      font-size: 100px;
      font-family: 'Roboto', sans-serif;
      color: black; /* default color */
    }
    CSS
    .reflection-text:before {
      content: "HELLO WORLD";
      position: absolute;
      top: 65px;
      transform: rotate(180deg) scaleX(-1);
      background: linear-gradient(to bottom, 
      rgba(0, 0, 0, 0) 20%, 
      rgba(0, 0, 0, 0.5) 60%, 
      rgba(0, 0, 0, 2) 100%);
      background-clip: text;
      color: transparent;
      opacity: 0.3;
    }
    CSS

    Purple Text

    .reflection-text {
      position: relative;
      font-size: 100px;
      font-family: 'Roboto', sans-serif;
      color: purple;
    }
    CSS
    .reflection-text:before {
      content: "HELLO WORLD";
      position: absolute;
      top: 65px;
      transform: rotate(180deg) scaleX(-1);
      background: linear-gradient(to bottom, 
      rgba(255, 55, 205, 0) 20%, 
      rgba(255, 55, 205, 0.5) 60%, 
      rgba(255, 55, 205, 2) 100%);
      background-clip: text;
      color: transparent;
      opacity: 0.3;
    }
    CSS

    Green Text

    .reflection-text {
      position: relative;
      font-size: 100px;
      font-family: 'Roboto', sans-serif;
      color: green;
    }
    CSS
    .reflection-text2:before {
      content:"HELLO WORLD";
      position: absolute;
      top: 65px;
      transform: rotate(180deg) scaleX(-1);
      background: linear-gradient(to bottom, 
      rgba(20, 150, 20, 0) 20%, 
      rgba(20, 150, 20) 60%, 
      rgba(20, 150, 20, 2) 100%);
      background-clip: text;
      color: transparent;
      opacity: 0.3;
    }
    CSS