Category: In the Browser

CSS, HTML, animations, and UI techniques that shape the web experience. Learn how to build beautiful, responsive, and interactive interfaces right in the browser.

  • Naming Conventions: How to Name Your Components Without Fighting Your UI Library

    Naming Conventions: How to Name Your Components Without Fighting Your UI Library

    At some point in pretty much every project, whether you’re setting up the infrastructure or introducing an important library that will be used throughout your app, you run into a tiny problem that turns out not to be so tiny: naming conventions.

    Let’s take a classic example.

    You need a <Modal />.
    Your UI library already has a <Modal />.

    So you open a file and write the imports, and suddenly you’re staring at something like this:

    import { Modal } from "@heroui/react";
    import { Modal } from "./my-components/Modal";
    JavaScript

    You see? You’re not the only one thinking Modal is a great name for a component about… well, a modal! In my case, I liked the name, but the developers building the HeroUI library also liked it.

    Now you have a small issue: how are you going to denote that a modal is one of yours, or that it’s imported from your UI library?

    In this example you’re probably thinking, “Well, maybe I’ll just rename one.” Obviously. Maybe <HeroModal />. Maybe <MyModal />. It works, JavaScript has no issues, TypeScript stops complaining, and you move on.

    The problem with this approach is that your code may start feeling noisy after a while. Not broken, but slightly uncomfortable. You might see different files using different aliases, which isn’t the best approach. This increases your cognitive load because you have to remember things instead of intuitively understanding them.

    That’s usually when people think the issue is naming.

    It’s not.

    What’s actually happening is that two completely different ideas are being treated like they’re the same thing.

    A library modal is just a tool. It renders a dialog, handles focus, animates, and gets out of the way.

    A modal in your app has meaning. It shows up for specific reasons. It follows product rules. It has opinions.

    Once you see that difference, naming stops being a guessing game.

    To avoid all this headache, the best thing you can do is stop for a bit, think about your approach, and decide what naming convention—a pattern, if you’d like—will help you intuitively understand what’s going on in your app without having to scroll up to your imports every time you see a component used.

    Naming convention 1: Your app owns “Modal”, the library is the “Base”

    This is the easiest convention, the one you probably thought about first. The idea behind this is:

    • Your app gets to use the “clean” name Modal
    • The UI library gets a more technincal name: ModalBase

    Example

    import { Modal as ModalBase } from "@heroui/react";
    JavaScript

    Then inside your component’s implementation would be:

    function Modal(props) {
      return <ModalBase {...props} />;
    }
    JavaScript

    Other examples for naming your components using this convention could be

    <ModalBase />
    
    <BaseModal />
    
    <HeroModal /> // (library-prefixed)
    
    <ModalCore />
    
    <UIModal />
    
    <ModalRaw />
    
    <RawModal />
    JavaScript

    Pros

    • ✅ Everyone on your team can use <Modal /> without worrying about where it came from.
    • ✅ If you ever change your UI library, you only change this wrapper, not your whole codebase.
    • ✅ Great for beginners because it keeps things simple and consistent.

    Cons

    • ❌ If your wrapper grows too much, it can become “magic”. Teammates may not be able to understand why the modal has more complex logic implementation
    • ❌ You must be disciplined with naming

    Naming convention 2: Name your modals based on what they actually do

    In this case you skip the generic name and instead name your modals based on what they are doing. This is helpful for large codebases, not small side projects.

    Examples of that could be:

    <EditProfileModal />
    
    <DeleteAccountModal />
    
    <InviteUserModal />
    
    <SettingsModal />
    
    <ShareModal />
    
    <ConfirmActionModal />
    
    <FeedbackModal />
    JavaScript

    Pros

    • ✅ Very clear meaning – you know what <DeleteAccountModal /> does just by reading it.
    • ✅ Great for beginners – easier to understand than a generic <Modal /> everywhere.

    Cons

    • ❌ Can repeat logic – if all modals need the same props or behavior, you might duplicate code.
    • ❌ Too many similar names – if you have lots of modals, the list can get long and harder to scan.

    Naming convention 3: Use prefix or suffix to show ownership

    If the word Modal confuses you because you are not sure where it came from, which is a valid point, you could ignore using the word Modal by itself and instead decide on a good suffix/prefix identifier.

    For your UI library component:

    <AppModal />
    
    <ProjectModal />
    
    <MainModal />
    
    <CoreModal />
    
    <ClientModal />
    
    <CustomModal />
    
    <ETModal /> // Prefixing your modal with your app's initials e.g Energy Tracker app
    JavaScript

    For your App component:

    <HeroModal />
    
    <LibModal />
    
    <UIModal />
    
    <ModalLib />
    JavaScript

    Pros

    • ✅ Very explicit – you can tell at a glance which modal is from your app vs the library.
    • ✅ Works well in mixed environments – e.g. multiple UI libraries, monorepos, shared packages.

    Cons

    • ❌ Names get longer – <AppModal />, <HeroModal /> are not as clean as <Modal />.
    • ❌ Can become inconsistent – if people invent new prefixes (<BaseModal />, <CoreModal />, <MainModal />) without a rule.

    Naming conventions that usually cause trouble

    Most teams try at least one of these at some point.

    MyModal sounds harmless but doesn’t mean anything to anyone else.

    CustomModal stops being descriptive the moment you have more than one.

    Library-branded names everywhere tie your feature code to a vendor, even when it shouldn’t care.

    Versioned names like Modal2 or NewModal are usually a sign that a decision was postponed, not solved.

    All of them work… until they don’t.

    A simple question that keeps things clean

    When naming feels hard, this question usually cuts through the noise:

    Is this a basic UI building block, or does it express actual product behavior?

    If it’s a tool, name it like one.
    Example: <ModalBase />, <InputPrimitive />, <ButtonCore />.

    If it’s intent, name it like intent.
    Example: <EditProfileModal />, <CreateProjectForm />, <DeleteAccountModal />.

    That’s the whole trick. You’ll know you’ve landed in a good place when your imports start feeling calm again:

    Wrapping up

    Naming might look like a small detail, but it affects how your whole project feels. Usually when I’m building a project and it’s time to decide on a UI library, I don’t want to spend time trying to identify names — I just start using whatever the import gives me and continue.

    The problem is that after a while I usually find myself needing to refactor because my app is getting more complex. You might say, “Well, it’s fine, you’re following the simple-now, refactor-later idea,” and you might be right. There’s a principle in programming, called YAGNI, that says you shouldn’t build complex systems just in case. You build infrastructure when you know you will need it soon.

    This applies directly to naming conventions.
    If you’re building a small side project just for fun, go ahead and use the UI library names like <Modal /> and skip the wrappers.

    But if you’re building an app you plan to present, monetize, or seriously grow, then stop for a moment, decide on your conventions, and then continue. The time you spend choosing now will be far less than the time you’ll lose later dealing with refactors and headaches.

    If you’re just getting started with app development, naming conventions are one of those topics that only start to matter after your environment is properly set up. If you’re still at that stage, you might find these guides useful before diving deeper into UI architecture:
    How to install Git on macOS
    How to install Homebrew on macOS
    How to install npm on macOS
    How to install PostgreSQL on macOS
    How to install Java on macOS

  • Simple Ways to Create a CSS Overlay Effect

    Simple Ways to Create a CSS Overlay Effect

    Have you ever wanted to add cool effects to your website? With the CSS overlay effect, you can easily create stylish overlays to make your content stand out! Let’s see how it works!

    What are overlay effects?

    A CSS overlay effect is a powerful technique for placing an extra layer on top of your web content, typically an image or a background, to enhance its appearance or improve readability.

    This effect allows you to create various visual enhancements, such as darkening an image or adding a color tint.

    You can achieve overlays using the CSS background-color and background-image properties, enabling you to apply stunning visual effects to images. With these properties, you can easily modify the look and feel of your content, making it more engaging and visually appealing.

    Let’s dive into an example to see how the CSS overlay effect works.

    Basic HTML and CSS setup for a CSS overlay effect

    First, we need to create an HTML element to hold our image and assign it a class. This class will contain all the necessary CSS rules to achieve the desired overlay effect.

    <div class="overlay-container"></div>
    HTML

    Next, we write the CSS for our class, setting a background image without repetition. This ensures the image fits nicely within a 400x600px box. With this setup, we can easily apply overlay effects or make further adjustments as needed.

    .overlay-container {
      width: 400px;
      height: 600px;
    
      background-image: url('your-image-url-here');
      background-repeat: no-repeat;
      background-size: cover;
    }
    CSS

    At this stage, this is how our image appears on the screen.

    Using pseudo-elements for the CSS overlay effect

    A common technique for creating overlay effects is pseudoelements (:before and :after). To get this effect working, we have to prepare our class by setting position: relative. Then, we apply position: absolute to the :before pseudo-element. This ensures that :before is positioned relative to its parent — the overlay container.

    We also use the content: "" declaration to make sure the pseudo-element is generated. In this case, the content remains empty since we want the image to be visible underneath.

    Additionally, we set width: 100%; and height: 100%; to ensure the :before pseudo-element covers the entire area of its parent container, completely overlaying the image.

    .overlay-container {
      ...
      position: relative;
    }
    
    .overlay-container:before {
      position: absolute;
      content: "";
      width: 100%;
      height: 100%;
    }
    CSS

    🔖 For the time being, nothing has changed on our screen; we just made the appropriate preparations for our effect. Let’s continue.

    Applying the CSS overlay effect

    Overlay effects come in various types, each adding a unique touch to our images. The CSS property that helps us to create this effect is background-image.

    Below, I’ve created different variations for you to explore. 👩‍💻 Enjoy!

    Using a linear gradient for the overlay effect

    In the following CSS code snippet, you can see that the background-image property is set to linear gradient(...), creating a multi-color overlay effect with different transparency levels. This produces a smooth gradient overlay from top to bottom with shades of teal, yellow, and purple that make the perfect match for our image.

    .overlay-container:before {
      ...
      background-image: linear-gradient(
        rgba(0, 255, 255, 0.3),
        rgba(255, 255, 0, 0.2),
        rgba(155, 0, 155, 0.2)
      );
    }
    CSS

    Using a radial gradient for the overlay effect

    We continue with a more creative approach. Here, radial gradient(...) creates a unique overlay effect using a circular pattern. It transitions from shades of light gray to dark gray, adding a subtle yet eye-catching touch to the image.

    .overlay-container:before {
      ...
      background-image: radial-gradient(
        rgba(255, 255, 255, 0.1),
        rgba(128, 128, 128, 0.2),
        rgba(0, 0, 0, 0.6)
      );
    }
    CSS

    Creating a rainbow CSS overlay effect

    Another vibrant and playful effect is the rainbow gradient. Often used for decorative purposes, this effect adds bright, joyful colors to the image, creating a fun and lively vibe. 🌈✨

    When you apply this gradient as a background, it creates a smooth transition of colors from purple to red, mimicking the colors of a rainbow (ROYGBIV). The use of semi-transparent alpha values gives a soft blending effect between the colors, creating a visually appealing and harmonious overlay.

    .overlay-container:before {
      ...
      background-image: linear-gradient(to bottom left,
        rgba(148, 0, 211, 0.5), rgba(75, 0, 130, 0.3),
        rgba(0, 0, 255, 0.2), rgba(0, 255, 0, 0.2),
        rgba(255, 255, 0, 0.3), rgba(255, 127, 0, 0.3),
        rgba(255, 0, 0, 0.3)
      );
    }
    CSS

    In this example, I changed my image to make the outcome clearer, adding a colorful vibe to create a playful atmosphere.

    Adding a solid color CSS overlay effect

    You are always free to use a single color as an overlay. In that case, we will apply the background-color CSS property to the :before pseudo-element.

    .overlay-container:before {
      ...
      background-color: rgba(220, 135, 135, 0.2); /* pale pink */
    }
    CSS

    In this example, I kept the second image to make the outcome clearer. I’ve given it a softer, more romantic feel, where the pale pink color with the slight see-through effect adds a charming and gentle mood.

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

  • Border-image-slice CSS Property For One-of-a-kind Border Effects

    Border-image-slice CSS Property For One-of-a-kind Border Effects

    The border-image-slice CSS property allows us to be extremely creative with our borders. We can cut (slice) a source, such as an image with a nice pattern or a gradient, into pieces so it can stretch or repeat those slices around an element’s border. We specify how far in from each edge the slicing occurs and those slices are sketched to be the border areas (edges and corners).

    Outline of the border-image-slice CSS property

    Let’s see our property more analytically. First, you pick a visual source and then decide where to “slice” it. After that, CSS uses those pieces to sketch the border. Kind of like cutting a picture into a nine-patch grid and placing it around a box.
    We have 4 corners, 4 sides, and the main content. Only 8 of them actually showed up and used for borders, the corners and the sides. The 9th slice, which is the main part of the element, is optional and it usually carries our content.

    A nine-patch grid outline about border-image-slice CSS property

    A few critical points about those pieces:

    • Corners: Depending on the value, they may not stretch (value 1), they just sit there like little anchors, or they may stretch (higher or more values).
    • Sides: Stretch or repeat, depending on your border settings. They control most of the visual essence.
    • Center: The middle part usually isn’t drawn as part of the border at all—it’s ignored unless you explicitly choose to fill it.

    Practical examples: How border-image-slice works

    To better understand how this property works, we first need to insert an image with a width and height of 400px.
    Next, we’ll apply properties like object-fit: cover, background-size: cover, and background-position: center to keep the image centered and fully visible without distortion.
    🔖 These properties are only here so we can clearly see the image at this stage — they aren’t required for the next steps.
    Finally, we add the source of our image.

    <div class="image"></div>
    HTML
    .image {
      width: 300px;
      height: 300px;
      
      object-fit: cover;
      background-position: center;
      background-size: cover;
      
      background-image:  url(https://images.unsplash.com/photo-1553526777-5ffa3b3248d8?ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&q=80&w=987);
    }
    CSS
    Image with pattern
    Photo by Robert Horvick on Unsplash

    With our image set up, we can continue and see how border-image-slice handles different inputs.

    This CSS property can take one to four values.
    One value: uses the same slice for every side.
    Two values: set the first for top and bottom, and the second for left and right.
    Three values: apply the first for the top, the second for both left and right and the third for the bottom.
    Four values: follow the standard CSS direction: top, left, bottom, right.
    With so many options, there is plenty of room to create some trully great-looking border effects.

    Setting the value: 1

    Let’s start with value 1.
    First, we need to add a 20px border but transparent. This gives us the space the image-based border will later occupy, without showing the standard solid border.

    Then, we set border-image-slice to 1. In this way, the browser takes a very thin section, just one pixel wide, from each edge of the image and stretches it along the borders. As a result, we have only stripes.

    .image {
      ...
      border: 20px solid transparent;
      border-image-slice: 1;
    }
    CSS
    Border effect setting the border-image-slice-value: 1

    Setting one value

    We continue following the same tactic, but this time instead of 1 we use a value of 100. By doing this, the browser cuts a 100-pixel-wide section from each edge of the image and uses those slices to form the new borders. In that way, we are closer to our initial image as we use a wider section of it.

    .image {
      ...
      border: 20px solid transparent;
      border-image-slice: 100;
    }
    CSS
    Border effect setting the border-image-slice-value: 100

    Setting two values

    Next, we will use two values, 1 100, to see how different slice sizes affect the borders. The first value (1) applies to both the top and bottom, creating thick slices, close to line-like borders. The second value (100) applies to both the left and right, creating wider slices that maintain more of the image’s details.

    .image {
      ...
      border: 20px solid transparent;
      border-image-slice: 1 100;
    }
    CSS
    Border effect setting the border-image-slice-value: 1 100

    Setting three values

    Moving forward, it’s time to see the results when using three values. The first value (150) applies to the top, the second value (80) to the left and right and finally the third value (5) to the bottom. As we can observe again, the higher the value, the closer to the image’s characteristics.

    .image {
      ...
      border: 20px solid transparent;
      border-image-slice: 150 80 5;
    }
    CSS
    Border effect setting the border-image-slice-value: 150 80 5

    Setting four values

    Our final option is to use four different values, one for each side of our element. The values apply in a clockwise direction – top, right, bottom, left. That creates an uneven but interesting border effect.

    .image {
      ...
      border: 20px solid transparent;
      border-image-slice: 50 80 120 150;
    }
    CSS
    Border effect setting the border-image-slice-value: 50 80 120 150

    Playing with border-image-slice feels a bit like trimming a photo into fancy frames — every small tweak shifts the mood of the border in surprising ways.
    What do you think? Are you ready to try it out yourself? Be my guest and have fun! 😃

  • Create Playful Border Effects Combining CSS Gradients With The Border-image-slice CSS Property

    Create Playful Border Effects Combining CSS Gradients With The Border-image-slice CSS Property

    Borders have long been one of the simplest tools in web design. Yet, that’s no reason to look boring. Combining the border-image-slice property with the power of CSS gradients, we can turn simple static lines into 🎨 colorful, eye-catching details that make your designs stand out. Besides, a playful border effect adds fun and energy to a page, helping shapes and sections feel more alive. No images needed, just blending colors with clean CSS.
    In other words, it’s a small touch that can make your design feel fresh and creative, adding personality and vibrance. 🌈 ✨

    Border effect explanation setting linear-gradient

    We’ll begin by creating a box with a 150px width and height that temporarily has a solid 5px black border. This is the box we’ll use to experiment with different gradient border effects and make it pop! 🥳

    <div class="box"></div>
    HTML
    .box {
      width: 150px;
      height: 150px;
      border: 5px solid;
    }
    CSS
    A white box with 5 pixels solid black border

    With our box in place, we can make things more interesting by replacing the simple black border with a color 🍭 splash of CSS gradients.

    • First, we need to add the transparent value to the border.
    • Next, we continue with the gradient. I decided to start with the linear-gradient and use three colors (magenta, cyan, orange). Feel free to use as many colors as you want.
    • In the final step, we set border-image-slice to 1. In that way, the browser uses the whole gradient evenly on all sides of the border.

    The browser doesn’t know how to spread the gradient across the border area. Without the border-image-slice property, the gradient won’t appear at all. It is essential to add it as it will activate and display the gradient border.

    .box {
      ...
      border: 5px solid transparent;
      border-image: linear-gradient(magenta, cyan, orange);
      border-image-slice: 1;
    }
    CSS
    Border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property

    It’s good to know that the border-image-slice property can take up to four values, each one responsible for how to cut (slice) the gradient we use as a border.

    More analytically:

    border-image-slice: 1; simply put the whole gradient eventually on all sides

    border-image-slice: 20; it cuts 20 (px or percentages, depending on what you use) from each edge to make the border

    border-image-slice: 20 30; the same as above but the first value is for top and bottom, the second for left and right

    border-image-slice: 20 30 10; the first value is for top, the second for left and right and the third for bottom

    border-image-slice: 20 30 10 5; finally, the first value is for top, the second for right, the third for bottom and the fourth for left

    🔖 When we use a gradient, we usually just write 1 because a gradient isn’t a picture with pixels or edges to slice. It smoothly fills the space, so there’s nothing to “cut”. The value 1 simply tells the browser to use the whole gradient for the border.

    More border effect ideas with linear-gradient technique and border-image-slice: 1

    Below, I included a few more examples to help you see how changing the gradient can completely transform the look of a border, making the concept clearer and easier to follow. 😃

    Flipping the colors: The reverse linear-gradient

    Colorful linear gradients that flow from top to bottom or the reverse way are like creating amazing color bands that wrap around the box.

    .box {
      ...
      border: 5px solid transparent;
      border-image: linear-gradient(to top, magenta, cyan, orange);
      border-image-slice: 1;
    }
    CSS
    Border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property

    Smooth side-to-side color flow with linear-gradient

    Colors travel from one side to the other, giving the border’s box a bright, balanced look.

    Firstly, from left to right

    .box {
      ...
      border: 5px solid transparent;
      border-image: linear-gradient(to right, magenta, cyan, orange);
      border-image-slice: 1;
    }
    CSS
    Border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property

    Then, from right to left

    .box {
      ...
      border: 5px solid transparent;
      border-image: linear-gradient(to left, magenta, cyan, orange);
      border-image-slice: 1;
    }
    CSS
    Border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property

    Playing with diagonal directions

    A diagonal direction gives the sense of a wavy, moving effect. Plus, changing the angle, you can create a more dynamic look.

    .box {
      ...
      border: 5px solid transparent;
      border-image: linear-gradient(45deg, magenta, cyan, orange);
      border-image-slice: 1;
    }
    CSS
    Diagonal border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property

    Color loops: The repeating linear-gradient technique

    With repeating gradients, you can build patterns that literally look like an impressive dancing effect or all these amazing neon light effects. How cool is that!? 😎

    .box {
      ...
      border: 5px solid transparent;
      border-image: linear-gradient(45deg, magenta, cyan, orange, magenta, cyan, orange, magenta, cyan, orange, magenta, cyan, orange, magenta, cyan, orange, magenta, cyan, orange, magenta, cyan, orange, magenta, cyan, orange, magenta, cyan, orange, magenta, cyan, orange, magenta, cyan, orange);
      border-image-slice: 1;
    }
    CSS
    Repeating border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property

    Moreover, we are free to experiment with the other two (radial-gradient and conic-gradient) CSS gradients as well. So, let’s dive into some more examples and discover how different gradient ideas come to life.

    Border effects with different border-image-slice values

    Radial gradient for spinning border effects

    Now, let’s see what would happen if we use the same gradient, in this case, the radial-gradient, with many different values on border-image-slice.
    For these examples, I used cyan, pink and violet. 🎨 ✨

    In the first example, we maintain the value 1 while in the second, we replace it with a value of 50.
    The border-image-slice: 1; applies the entire gradient, spreading the colors smoothly around the border. With this transition, the gradient stays wide and soft.

    .box {
      ...
      border: 5px solid transparent;
      border-image: radial-gradient(cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet);
      border-image-slice: 1;
    }
    CSS
    Border effect with cyan, pink and violet made combining the radial-gradient technique and the border-image-slice: 1 CSS property


    The border-image-slice: 50; applies a small piece of the gradient. Since it’s using only a part of the gradient’s color range, the colors repeat more often and look like stripes that are spinning around.

    .box {
      ...
      border: 5px solid transparent;
      border-image: radial-gradient(cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet, cyan, pink, violet);
      border-image-slice: 50;
    }
    CSS
    Border effect with repeating stripes from cyan, pink and violet made combining the radial-gradient technique and the border-image-slice: 50 CSS property

    To sum up, increasing the slice value tells the browser to take a smaller “slice” of the gradient and reuse it around the border. As a result, with a smaller slice, we have more repetition and eventually stronger striping.

    Conic gradient for more complex border effect

    Next, let’s see what would happen if we use the same gradient, in this case, the conic-gradient, but different values on border-image-slice.
    For these examples, I changed the colors and used black, orange, magenta, and black again. 🎨 ✨

    🔖 A small detail to keep in mind is that starting and ending with the same color (in this case, black) helps to keep the transitions soft and seamless.

    .box {
      ...
      border: 5px solid transparent;
      border-image: conic-gradient(black, orange, magenta, black);
      border-image-slice: 1;
    }
    CSS
    Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 1 CSS property

    Conic-gradient with repeating pattern

    In this case, with a 1 value it uses almost the entire conic gradient around the border. The colors flow smoothly and evenly, creating a soft circular blend with gentle transitions.

    .box {
      ...
      border: 5px solid transparent;
      border-image: conic-gradient(black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta,black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black);
      /* all around the same value */
      border-image-slice: 1;
    }
    CSS
    Repeating border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 1 CSS property

    On the other hand, with a value 30 it takes a smaller portion of the gradient and stretches it around the border. The border starts showing clearer color sections with mild curves and slight breaks at the corners.

    .box {
      ...
      border: 5px solid transparent;
      border-image: conic-gradient(black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta,black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black);
      /* all around the same value (30) */
      border-image-slice: 30;
    }
    CSS
    Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 30 CSS property

    Finally, with a value of 60 it uses a very small wedge of the conic gradient and repeats it. As a result, the border shows strong, repeating color bands or striped details, especially near the corners.

    .box {
      ...
      border: 5px solid transparent;
      border-image: conic-gradient(black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta,black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black);
      /* all around the same value (60) */
      border-image-slice: 60;
    }
    CSS
    Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 60 CSS property

    In this case, we use two values: 1 60. The result is a creative mix of two effects. The first value (1) applies to the top and bottom borders. Due to this we have a smooth and gentle look with wide color transitions. The second value (60) applies to both the left and right borders. Because of that, the effect is a tighter and more striped pattern as the gradient slice we use is smaller and repeated more often.

    .box {
      ...
      border: 5px solid transparent;
      border-image: conic-gradient(black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta,black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black);
      /* top & bottom - left & right */
      border-image-slice: 1 60;
    }
    CSS
    Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 1 60 CSS property

    Our final example takes four values: 1 60 60 1. This setup makes our border appear acymatric, calm, and energetic at the same time. More analytically, the first value (1) is for the top border and uses almost the entire gradient. The second and the third values (60 60) are for the right and bottom borders and use a smaller slice (tighter pattern). While the last value (1) is for the left border and uses almost the entire gradient again. Due to these values, we have smooth and continuous top and right borders, while the bottom and left are striped.

    .box {
      ...
      border: 5px solid transparent;
      border-image: conic-gradient(black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta,black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black, orange, magenta, black);
      /* top - right - bottom - left */
      border-image-slice: 1 60 60 1;
    }
    CSS
    Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 1 60 60 1 CSS property

    Conic-gradient with color stops

    Furthermore, we can control the color stops by using percentages, allowing us to decide exactly where the colors start and end each time.

    .box {
      ...
      border: 5px solid transparent;
      border-image: conic-gradient(black 75%, orange 75%, magenta 80%, black 85%,  black 90%, magenta 95%, orange 100%);
      border-image-slice: 1;
    }
    CSS
    Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 1 CSS property
    .box {
      ...
      border: 5px solid transparent;
      border-image: conic-gradient(black 0%, black 5%, magenta 5%, magenta 10%, black 10%, black 15%, magenta 15%, magenta 20%, black 20%, black 25%, magenta 25%, magenta 30%, black 30%, black 35%, magenta 35%, magenta 40%, black 40%, black 45%, magenta 45%, magenta 50%, black 50%, black 55%, magenta 55%, magenta 60%, black 60%, black 65%, magenta 65%, magenta 70%, black 70%, black 75%, magenta 75%, magenta 80%, black 80%, black 85%, magenta 85%, magenta 90%, black 90%, black 95%, magenta 95%, magenta 100%);
      border-image-slice: 1;
    }
    CSS
    Border effect with black and magenta stripes made combining the conic-gradient technique and the border-image-slice: 1 CSS property

    The results we observe when utilizing these all these specific values above on the border-image-slice CSS property concerns only a box of 150 pixels in width and height. It is critical to adjust the values if you have different dimensions.

    Take into consideration that gradients with the 1 value look better in square shapes, as the color flow fits perfectly within equal sides.

    Experimenting with gradient borders opens the door to an endless palette of styles — from soft pastel outlines that frame content elegantly to bold, vibrant strokes that command attention. The key lies in balance: using color transitions and subtle motion to enhance, not overpower, the user experience. Whether you’re styling buttons, containers, or entire sections, CSS gradient borders are a reminder that even the smallest design detail can carry a playful spark — proof that borders don’t just separate elements, they can also bring them to life.

  • Clip-path Inset CSS Property – Cropping Elements As A Pro

    Clip-path Inset CSS Property – Cropping Elements As A Pro

    Another efficient and user-friendly CSS method to cut down ✂ and “play” 🤹‍♀️ with existing HTML elements. In contrast to most clip-path methods that use coordinate pairs(X, Y) to define points (that act as the corners of the shape) inset() manipulate the sides of the element. How so? Let’s discover it together!

    The clip-path: inset() is a way to restrict the visible area of an element by “pushing in” its sides from the element’s bounding box. This function doesn’t create a new shape as every element’s box is rectangular (and it can be a square if the width and height match), it just “trims” the existing one. The result is always a four-sided shape with right angles, which can be either a rectangle or, in special cases, a square.

    Now, let’s proceed with a more detailed analysis and try out this amazing tool. For better understanding, I have prepared some practical examples for you. This is our “working area” for today! 👷‍♀️ 🏗 👷‍♂️

    Clip-path: inset() function explained

    First things first. What does this mean? Well.. We need a rectangular or a square shape in order to work with clip-path: inset() CSS property.

    The following code snippet and image illustrate how we create a simple black square with 200px width and 200px height.

    /* square */
    .square-shape {
      width: 200px;
      height: 200px;
      background-color: black;
      }
    CSS
    A black square with 200px width and height

    Inset accepts up to four values, each controlling how far the sides are pushed inward.

    So, how about analyzing the different cases based on these values, and then proceeding with examples?

    • One value: it applies to all four sides
    • Two values: the first one is for top & bottom, while the second is for left & right
    • Three values: the first one is for top, the second for left & right and the third for bottom
    • Four values: the first one is for top, the second for left, the third for bottom and finally the fourth value is for the right side (clockwise).

    We can now proceed with our examples. The code snippets and images that follow display these four cases.

    First case – One value

    .square-shape {
      ...
      clip-path: inset(50px);
      }
    CSS
    A black square with 100 pixels width and height. Applying to all sides clip-path: inset(50px);

    NOTE: ⬜ The gray color is used only for clarity, to distinguish the initial square from the clipped one. In practice, this part would be cut out (hidden).

    Second case – Two values

    .square-shape {
      ...
      clip-path: inset(20px 30px);
      }
    CSS
    A black square with 100 pixels width and height. Applying to all sides clip-path: inset(20px 30px);

    Third case – Three values

    .square-shape {
      ...
      clip-path: inset(20px 30px 10px);
      }
    CSS
    A black square with 100 pixels width and height. Applying to all sides clip-path: inset(20px 30px 10px);

    Fourth case – Four values

    .square-shape {
      ...
      clip-path: inset(20px 40px 10px 30px);
      }
    CSS
    A black square with 100 pixels width and height. Applying to all sides clip-path: inset(20px 40px 10px 30px);

    Making your elements smooth with rounded corners

    Apart from cropping, inset() allows you to round the corners of the clipped shape as well. This is achieved by adding the optional round keyword, followed by a radius value, which functions similarly to the border-radius CSS property.
    By utilizing it, we can transform the sharp corners into rounded ones.

    As previously with the inset(), round takes up to four values, too.

    • One value: it applies to all corners the same value
    • Two values: they applied diagonal, the first one is for top-left & bottom-right corners, while the second is for top-right & bottom-left corners
    • Three values: the first one is for the top-left corner, the second goes diagonally and is applied to both the top-right & bottom-left corners, and the third for the bottom-right corner
    • Four values: the first one is for the top-left corner, the second for the top-right, the third for the bottom-right, and finally the fourth value is for the bottom-left corner (clockwise).

    We move forward with our examples. The following code snippets and images display these four cases.

    First case – One value

    .square-shape {
      ...
      clip-path: inset(50px round 25px);
      }
    CSS
    A black square with 100 pixels width and height. Applying clip-path: inset(50px round 25px);

    Second case – Two values

    .square-shape {
      ...
      clip-path: inset(50px round 0px 25px);
      }
    CSS
    A black square with 100 pixels width and height. Applying clip-path: inset(50px round 0px 25px);

    Third case – Three values

    .square-shape {
      ...
      clip-path: inset(50px round 0px 25px 10px);
      }
    CSS
    A black square with 100 pixels width and height. Applying clip-path: inset(50px round 0px 25px 10px);

    Fourth case – Four values

    .square-shape {
      ...
      clip-path: inset(50px round 0px 25px 10px 20px);
      }
    CSS
    A black square with 100 pixels width and height. Applying clip-path: inset(50px round 0px 25px 10px 20px);

    Apart from pixels, all values can also be written in percentages. The two units, px and %, can even be combined.

    The following examples, along with their code snippets and images, illustrate these cases.

    Using percentages as values

    .square-shape {
      ...
      clip-path: inset(25% round 0% 25% 5% 10%);
      }
    CSS
    A black square with 100 pixels width and height. Applying clip-path: inset(25% round 0% 25% 5% 10%);

    Combine percentages with pixels

    .square-shape {
      ...
      clip-path: inset(25% round 10px 30% 5% 60px);
      }
    CSS
    A black square with 100 pixels width and height. Applying clip-path: inset(25% round 10px 30% 5% 60px);

    Well, something like a 🍋 lemon is here!! Cool, hug!?

    Clip-path inset function – manipulating images

    Images can also be clipped, revealing only part of them, by simply utilizing the clip-path: inset() CSS property.

    Below, we have an image of a bicycle 🚴‍♀️ out in nature. 🏞 Let’s say that we want to isolate the bicycle and display it within a rounded shape, pretty much like a frame. ✨

    An image with 100px width and height, showing a bicycle in nature.


    Depending on our prefrences, we cut away the unnecessary parts. First, our initial square image turns into a rectangle. After that, we add the round with a value of 50% which gives the remaining part a smooth, nicely rounded shape.

    NOTE: To make things more straightforward, I’ve prepared an image with colored code and overlays 🎨 ✂ showing which values correspond to the parts we cut away.

    .image {
      ...
      clip-path: inset(47px  14px  7px  20px  round 50%);
      }
    CSS

    Now we see just the bicycle kept in view, while everything else is clipped out. Exactly the effect we want to achieve.

    An image with 100px width and height, showing a bicycle in nature. Applying clip-path: inset(47px 14px 7px 20px round 50%);

    Voila!! There we have it! Our final updated image!! 🥳 Ready to be styled even more with all those amazing CSS properties!

    A rounded image showing a bicycle
  • Clip-path For Simplified Triangles – Ready Code-To-Copy

    Clip-path For Simplified Triangles – Ready Code-To-Copy

    Have you come across the clip-path CSS property before? It’s a unique tool that helps us to create a variety of shapes from scratch without the need for complex code. A trully captivating addition in web design.

    The clip-path accepts several values: circle(), ellipse(), polygon(), and inset(). These values define the shape of the clipping path applied to an element and we utilize them depending on the shape we want to create each time.
    Specifically, in today’s post, we will learn how to clip an element into a triangle shape by setting the clip-path: polygon().

    Clip-path polygon() function explained

    It’s time to continue and focus on our triangles. Let’s proceed with the example I prepared and see how this special tool works. 🪄 Below we have a black square. We used to create squares by setting the width and height CSS properties, but for today, let’s see how we can replace them with the clip-path property.

    Take a look below. I begin with a ⬛ square, making it easier to understand our function as squares (boxes) are the most familiar shapes in CSS. Then I will transform this square into a 📐 triangle. The color code shows how we position the square along both the X-axis and Y-axis. The colored points on the corners represent the clipping region.

    🖇 Despite having three magenta points and one green point, for now, all points behave the same. The differentiation of the green point will be meaningful later and hold significance for the following stages in our work.

    A square made by setting the clip-path: polygon(0% 0%,100% 0%,100% 100%, 0% 100%);

    Each pair of values inside the clip-path: polygon() function represents a point, and all these points together define a clipping region.

    Create orthogonal triangles

    Now, let’s see how we can transform it into a triangle. The square has four corners (points) while the triangle has three corners. Depending on the type of triangle we want to create, we need to cut the corresponding corner.
    In my example, I create an orthogonal triangle. I cut the top-right corner (100% 0%). As you can see in the following image, cutting this corner, we have the triangle we need.

    An orthogonal triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);

    What do you think? It looks good! Isn’t it? 😎 With just a simple line of code!

    🔖 I opted to clip the top-right corner (100% 0%). Alternatively, it would also be correct to clip the top-left corner (0% 0%), the bottom-right corner (100% 100%), or the bottom-left corner (0% 100%). All these clippings yield the same result, so you can choose the one that best fits your preferences. Additionally, you can use transform: rotate to adjust the orientation as needed.

    Creating orthogonal triangles setting the clip-path CSS property.

    With our triangles now in place, let’s explore how we can move them along both axes and discover the variety of triangles we can create.

    Create equilateral triangles

    We move forward by keeping the initial design where we cut the top-right corner (100% 0%). We will work with this triangle.

    To start, I’ve chosen to create equilateral triangles. This involves first focusing on the remaining top-left corner and then on the remaining bottom-right corner. Don’t worry and don’t feel confused, we’ll clear everything up. As mentioned above, the code and diagrams for clarity are ready!

    As you can see below, we maintain the bottom corners as they are, and we change the remaining top-right corner, where we move it left to 50% along the X-axis. By doing so, we transform our orthogonal triangle into an equilateral triangle.

    clip-path: polygon(
               50% 0%,
               100% 100%,
               0% 100%);
    Two triangles. On the left we see a square made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right we see an An orthogonal triangle made by setting the clip-path: polygon(50% 0%,100% 100%,0% 100%);

    This orthogonal triangle can give us one more equilateral triangle. We maintain the top-left and bottom-left corners, and we change the bottom-right corner by moving it up to 50%on the Y-axis.

    clip-path: polygon(
               0% 0%,
               100% 50%,
               0% 100%);
    Two triangles. On the left we see an orthogonal triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right we see an equilateral triangle made by setting the clip-path: polygon(0% 0%,100% 50%,0% 100%);

    Create acute triangles

    We continue with the acute triangles. Once again, we maintain the bottom corners as they are, and we change the remaining top-right corner. Here, we have two cases. First, we move it left to 15% along the X-axis, while in the second case, we move it left to 85%. By doing so, we transform our orthogonal triangle into acute triangles. Depending on our preferences.

    clip-path: polygon(
               15% 0%,
               100% 100%,
               0% 100%);
    Two triangles. On the left we see a an orthogonal triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right we see an acute triangle made by setting the clip-path: polygon(15% 0%,100% 100%,0% 100%);
    clip-path: polygon(
               85% 0%,
               100% 100%,
               0% 100%);
    Two triangles. On the left we see an orthogonal triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right we see an An acute triangle made by setting the clip-path: polygon(85% 0%,100% 100%,0% 100%);

    Another approach is to work with the bottom-right corner and adjust the values on the Y-axis. Let’s see how our triangle will become then. I move the bottom-right corner first up to 35% and then up to 65%.

    clip-path: polygon(
               0% 0%,
               100% 35%,
               0% 100%);
               /* OR */
    clip-path: polygon(
               0% 0%,
               100% 65%,
               0% 100%);
    Two acute triangles. On the left it is made by setting the clip-path: polygon(0% 0%,100% 35%,0% 100%);
while on the right it is made by setting the clip-path: polygon(0% 0%,100% 65%,0% 100%);

    🔖 The values I use to create the triangles are indicative. Feel free to choose any value that suits your preferences and requirements. 😃

    Create obtuse triangles


    Finally, it’s time to work with the bottom-left corner. We leave the top-left and bottom-right corners unchanged while modifying the values of the bottom-left corner. Initially, I adjust the X-axis value, shifting the corner left to 20%. Next, I adjust the Y-axis value, moving the corner up to 80%.

    clip-path: polygon(
               0% 0%,
               100% 100%,
               20% 100%);
    Two triangles. On the left we see an orthogonal triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right we see an obtuse triangle made by setting the clip-path: polygon(0% 0%,100% 100%,20% 100%);
    clip-path: polygon(
               0% 0%,
               100% 100%,
               0% 80%);
    Two triangles. On the left we see a an orthogonal triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right we see an obtuse triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 80%);

  • Clip-path For Navigation Signs – Ready Code-To-Copy

    Clip-path For Navigation Signs – Ready Code-To-Copy

    Have you ever wondered if you can create all these directional signs (⬆,↙, etc.), you see everywhere around, using only CSS? I have the solution for you! What about exploring the unique clip-path CSS property, where you can create complex shapes following specific movements!

    The clip-path property allows us to cut ✂ an element to a shape of our choice by specifying a series of points. It takes many values, but in our case, we will use the clip-path: polygon() function. I’ll briefly note circle(), ellipse(), and inset() which are the rest of the functions. In this post, we will analyze how we can create navigation signs only.

    Clip-path: polygon() function explained

    It would be an excellent start to examine the syntax of this amazing tool. Below I’ve illustrated the code along with explanatory diagrams.
    The first one shows how we can make a square setting the clip-path: polygon() function. We used to create square shapes ⬛ by simply setting the width and height CSS properties. However, I opted to use the clip-path to utilize its familiarity and improve clarity. 😎
    I used colored code to show you how we measured on both the axis-X and axis-Y. Each pair of values represents a point, with the first value indicating the horizontal position and the second value indicating the vertical position. Then an image accompanied the code and display a series of colored points illustrate how we form our visual element.

    Creating square with clip-path: polygon() function - clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);

    “Clip-path is extremely flexible. We can create any shape we desire from scratch, but we can also apply it to existing shapes and create transformations of our choice”.

    The second case shows how we can transform the square into a directional sign that points to the top. Again, the clip-path: polygon function is defined by coordinates relative to the element’s bounding box, but this time it is a bit harder. 🤯 Don’t worry, I am here to clarify for you! 🤓

    • It starts at the top-middle (50% 0%).
    • Then it moves diagonally down and right (70% 25%).
    • From there, it continues straight down (70% 100%) where it turns diagonally again for two times in a row.
    • First up and left (50% 75%), then down and left (30% 100%).
    • Finally, it moves straight up (30% 25%) where it completes its movements.
    Creating a shape 'direction to up' with clip-path: polygon() function - clip-path: polygon(50% 0%, 70% 25%, 70% 100%, 50% 75%, 30% 100%, 30% 25%);

    These one-direction moves enable you to create complicated shapes by strategically placing each point to outline the desired polygonal form. This method allows for precise control over the path of the shape, facilitating the design of visually appealing and geometrically complex elements on web pages.

    Ready-to-copy code snippets

    Below, I have prepared ready-to-copy code for directional signs. Feel free to use it everywhere you need. Enjoy! 🎊

    Directions

    Ready code and explanation diagrams for directions.

    Direction to Up

    clip-path: polygon(
               50% 0%,
               70% 25%,
               70% 100%,
               50% 75%,
               30% 100%,
               30% 25%);
    Creating a shape 'direction to up' with clip-path: polygon() function. clip-path: polygon(
           50% 0%,
           70% 25%,
           70% 100%,
           50% 75%,
           30% 100%,
           30% 25%);

    Direction to Down

    clip-path: polygon(
               30% 0%,
               50% 25%,
               70% 0%,
               70% 75%,
               50% 100%,
               30% 75%);
    Creating a shape 'direction to down' with clip-path: polygon() function. clip-path: polygon(
           30% 0%,
           50% 25%,
           70% 0%,
           70% 75%,
           50% 100%,
           30% 75%);

    Direction to the Left

    clip-path: polygon(
               25% 30%,
               100% 30%,
               75% 50%,
               100% 70%,
               25% 70%,
               0% 50%);
    Creating a shape 'direction to left' with clip-path: polygon() function. clip-path: polygon(
           25% 30%,
           100% 30%,
           75% 50%,
           100% 70%,
           25% 70%,
           0% 50%);

    Direction to the Right

    clip-path: polygon(
               0% 30%,
               75% 30%,
               100% 50%,
               75% 70%,
               0% 70%,
               25% 50%);
    Creating a shape 'direction to right' with clip-path: polygon() function. clip-path: polygon(
           0% 30%,
           75% 30%,
           100% 50%,
           75% 70%,
           0% 70%,
           25% 50%);

    🔖 We are always free to skip all these signs and create just one, 😇 to show only one direction, then we can rotate it until it aligns with our preferences.

    Arrows

    Ready code and explanation diagrams for arrows.

    Arrow up

    clip-path: polygon(
               50% 0%,
               100% 25%,
               75% 25%,
               75% 100%,
               25% 100%,
               25% 25%,
               0% 25%);
    Creating a shape 'arrow to up' with clip-path: polygon() function. 
clip-path: polygon(
           50% 0%,
           100% 25%,
           75% 25%,
           75% 100%,
           25% 100%,
           25% 25%,
           0% 25%);

    Arrow down

    clip-path: polygon(
               25% 0%,
               75% 0%,
               75% 75%,
               100% 75%,
               50% 100%,
               0% 75%,
               25% 75%);
    Creating a shape 'arrow to down' with clip-path: polygon() function. clip-path: polygon(
           25% 0%,
           75% 0%,
           75% 75%,
           100% 75%,
           50% 100%,
           0% 75%,
           25% 75%);

    Arrow to the left

    clip-path: polygon(
               25% 0%,
               25% 20%,
               100% 20%,
               100% 80%,
               25% 80%,
               25% 100%,
               0% 50%);
    Creating a shape 'arrow to the left' with clip-path: polygon() function.
clip-path: polygon(
           25% 0%,
           25% 20%,
           100% 20%,
           100% 80%,
           25% 80%,
           25% 100%,
           0% 50%);

    Arrow to the right

    clip-path: polygon(
               75% 0%,
               100% 50%,
               75% 100%,
               75% 80%,
               0% 80%,
               0% 20%,
               75% 20%);
    Creating a shape 'arrow to the right' with clip-path: polygon() function.
clip-path: polygon(
           75% 0%,
           100% 50%,
           75% 100%,
           75% 80%,
           0% 80%,
           0% 20%,
           75% 20%);

    Points

    Ready code and explanation diagrams for points.

    Point up

    clip-path: polygon(
               50% 0%,
               100% 25%,
               100% 100%,
               0% 100%,
               0% 25%);
    Creating a shape 'point up' with clip-path: polygon() function. 
clip-path: polygon(
           50% 0%,
           100% 25%,
           100% 100%,
           0% 100%,
           0% 25%);

    Point down

    clip-path: polygon(
               0% 0%,
               100% 0%,
               100% 75%,
               50% 100%,
               0% 75%);
    Creating a shape 'point down' with clip-path: polygon() function. 
clip-path: polygon(
           0% 0%,
           100% 0%,
           100% 75%,
           50% 100%,
           0% 75%);

    Point left

    clip-path: polygon(
               25% 0%,
               100% 0%,
               100% 100%,
               25% 100%,
               0% 50%);
    Creating a shape 'point left' with clip-path: polygon() function. 
clip-path: polygon(
           25% 0%,
           100% 0%,
           100% 100%,
           25% 100%,
           0% 50%);

    Point right

    clip-path: polygon(
               0% 0%,
               75% 0%,
               100% 50%,
               75% 100%,
               0% 100%);
    Creating a shape 'point right' with clip-path: polygon() function. 
clip-path: polygon(
           0% 0%,
           75% 0%,
           100% 50%,
           75% 100%,
           0% 100%);
  • Clip-path For Quick Polygons – Ready Code-To-Copy

    Clip-path For Quick Polygons – Ready Code-To-Copy

    Welcome! Today we’ll dig ⛏ deep and dive into geometric layouts exploring the fascinating clip-path CSS property. This amazing tool helps us to define specific regions within an element, allowing creative shape manipulation. We declare specific points based on the shape we intend to create, offering precise control over our work preferences and needs.

    Clip-path CSS property supports several shapes. Depending on the shape we want to create we have the following options: circle(), ellipse(), inset(), and polygon(). In today’s post we’ll spend time on clip-path: polygon() as this anables us to clip an element into a polygon shape.

    Clip-path polygon() function explained

    To illustrate the clip-path: polygon() CSS property I chose to start with a square, as it is the most common type of polygon.
    Below, we can see the code marked with colors. Each pair of values, inside the parentheses, symbolizes a point. In our case, we have four pairs of values, hence we have a shape with four points (square).
    The four color points represent the clipping area and display how we position the square on both axes X and Y.

    /* square */
    clip-path: polygon(
               0% 0%,
               100% 0%,
               100% 100%,
               0% 100%);
    CSS
    A square with highlight marks, positioned on both X and Y axes.

    Below is ready-to-copy code for polygons. Feel free to use it wherever you need! 🤗

    Create pentagon

    /* pentagon */
    clip-path: polygon(
               50% 0%,
               100% 40%,
               80% 100%,
               20% 100%,
               0% 40%);
    CSS
    A pentagon with highlight marks, positioned on both X and Y axes.
    /* pentagon oriented downward */
    clip-path: polygon(
               20% 0%,
               80% 0%,
               100% 60%,
               50% 100%,
               0% 60%);
    CSS
    A pentagon oriented downward with highlight marks, positioned on both X and Y axes.

    Create hexagon

    /* hexagon vertical */
    clip-path: polygon(
               25% 0%,
               75% 0%,
               100% 50%,
               75% 100%,
               25% 100%,
               0% 50%);
    CSS
    A vertical hexagon with highlight marks, positioned on both X and Y axes.
    /* hexagon horizontal */
    clip-path: polygon(
               50% 0%,
               100% 25%,
               100% 75%,
               50% 100%,
               0% 75%,
               0% 25%);
    CSS
    A horizontal hexagon with highlight marks, positioned on both X and Y axes.

    Create heptagon

    /* heptagon */
    clip-path: polygon(
               50% 0%,
               90% 20%,
               100% 60%,
               75% 100%,
               25% 100%,
               0% 60%,
               10% 20%);
    CSS
    A heptagon with highlight marks, positioned on both X and Y axes.
    /* heptagon oriented downward */
    clip-path: polygon(
               25% 0%,
               75% 0%,
               100% 40%,
               90% 80%,
               50% 100%,
               10% 80%,
               0% 40%);
    CSS
    A heptagon oriented downward with highlight marks, positioned on both X and Y axes.

    Create octagon

    clip-path: polygon(
               30% 0%,
               70% 0%,
               100% 30%,
               100% 70%,
               70% 100%,
               30% 100%,
               0% 70%,
               0% 30%);
    CSS
    An octagon with highlight marks, positioned on both X and Y axes.

    Create nonagon

    /* nonagon */
    clip-path: polygon(
               50% 0%,
               83% 12%,
               100% 43%,
               94% 78%,
               68% 100%,
               32% 100%,
               6% 78%,
               0% 43%,
               17% 12%);
    CSS
    A nonagon with highlight marks, positioned on both X and Y axes.
    /* nonagon oriented downward */
    clip-path: polygon(
               32% 0%,
               68% 0%,
               95% 23%,
               100% 57%,
               85% 87%,
               50% 100%,
               15% 87%,
               0% 57%,
               5% 23%);
    CSS
    A nonagon oriented downward with highlight marks, positioned on both X and Y axes.

    Create decagon

    clip-path: polygon(
               50% 0%,
               80% 10%,
               100% 35%,
               100% 65%,
               80% 90%,
               50% 100%,
               20% 90%,
               0% 65%,
               0% 35%,
               20% 10%);
    CSS
    A decagon with highlight marks, positioned on both X and Y axes.

    Adjust polygon rotation for simplicity

    To make things easier, we are free to create only one type of shape at a time and adjust its direction by customizing its orientation.
    For instance, as demonstrated below, we can use a decagon shape, which is the last shape we created above, and modify its degrees through the transform: rotate() CSS property. In that way, we set the orientation according to our preferences.

    More specifically:

    • In case 1, we notice our decagon rotating 90 degrees to the right
    • In case 2, with the use of a negative value, our decagon moves anticlockwise and rotates 90 degrees to the left
    • In case 3, it rotates 180 degrees to the right, resembling a downward orientation

    🔖 Pay attention to how the colorful dots shift from one place to another, updating their positions each time we change the rotating value. 🥳

    /* case 1 */
    transform: rotate(90deg);
    /* case 2 */
    transform: rotate(-90deg);
    /* case 3 */
    transform: rotate(180deg);
    CSS
    A decagon with highlight marks and 90 deg rotation, positioned on both X and Y axes.
    A decagon with highlight marks and -90 deg rotation, positioned on both X and Y axes.
    A decagon with highlight marks and 180 deg rotation, positioned on both X and Y axes.
  • Easy Made Circles – A Simple Guide to clip-path CSS Property

    Easy Made Circles – A Simple Guide to clip-path CSS Property

    The clip-path property in CSS lets you control which part of an element is visible by defining a specific shape, no matter what the element’s shape is. It’s like placing a mask over an element—only the area inside the shape will be shown. Everything outside will be hidden. This provides a clever way to “cut out” parts of an element without needing extra images or complex code.

    A great tool for creating unique layouts, applying image effects, and designing custom shapes. CSS supports several shapes for clip-path, including circle(), ellipse(), inset(), and polygon()—each giving you different ways to shape your content and hide any parts you don’t need. 🪄

    In today’s post, we’ll focus on the circle() ⚫ function and explore how it works. 🧐
    Let’s dive in!

    The circle() function

    The circle() function is one of the simpler ways to create circles by clipping an element into a rounded shape with a radius of our preference based on the element’s smaller dimension (width or height, selecting the smaller one, ensuring the circle fits within the element).
    Traditionally, we can use pixels px and percentages % to define the dimensions and the position of the circle. Otherwise, we can just utilize the handy center keyword, which is responsible for positioning our circle.

    Below, we see the starting setup we’ll use to explore this awesome CSS property. It shows a dark grey square, with a width and height of 200px. Also, a small white dot marks its center. This allows us to visualize exactly how the circle is positioned. The square is placed on an axis to make things even clearer.
    This helps explain both positioning and how the circle will be clipped inside it (inside the square element). 📐 😃

    A square we will transform to a circle using clip-path: circle()

    The circle(radius at axis-X axis-Y) function using pixels and percentages

    It defines a circular clipping area using two values: the radius of the circle and its center point. We set the radius to 100px wide or 50% of the element’s width, and we positioned it 100px from the left and 100px from the top of the element or 50% 50%, which places the circle right in the element’s center. Everything outside the circle will be invisible.
    This creates a circle that is perfectly centered within the square.

    .circle {
          // circle(radius at axis-X axis-Y) //
    clip-path: circle(100px at 100px 100px);
    }
                  // OR //
    .circle {
       // circle(radius at axis-X axis-Y) //
    clip-path: circle(50% at 50% 50%);
    }
    CSS
    A perfectlry centered circle with a 50% radius using clip-path

    Now, let’s try to cut ✂ a smaller circle. Maybe with a radius of 80px. How would our code and circle look now? Check out the updated code snippet below.

    We’re still cutting out a specific shape, a circle, from the element, but this time the circle is smaller (radius of 80px or 40% of the element’s width), though it is centered at the same spot as before (100px from the left and 100px from the top or 50% 50%). That means the circle stays perfectly centered within the square.

    .circle {
    clip-path: circle(80px at 100px 100px);
    }
                  // OR //
    .circle {
    clip-path: circle(40% at 50% 50%);
    }
    CSS
    A perfectlry centered circle with a 40% radius using clip-path

    🔖 Bear in mind that we can combine pixels with percentages, too. E.g. clip-path: circle(80px at 50% 50%);

    Using % instead of pixels, it makes our shapes responsive and adjusts to the size of our elements each time. In that way, our designs are more flexible and adaptable to different screen sizes.

    The circle(radius) function

    Another way to create circles using clip-path is the circle(%). It clips the element into a perfect circle with a radius of our preference. Additionally, since you do not specify a position, it centers by default at 50% 50% (50% horizontally and 50% vertically).

    Below, we have two examples. The first one has a radius of 50%, while the second has a radius of 40%, allowing for easy comparison with the previous examples.

    .circle {
    clip-path: circle(50%);
    }
          // OR //
    .circle {
    clip-path: circle(40%);
    }
    CSS
    A perfectlry centered circle with a 50% radius using clip-path
    A perfectlry centered circle with a 40% radius using clip-path

    The circle(radius at center) function using the ‘center’ keyword

    It defines a circular clipping area using the radius and the keyword center. Using this method, we create a circle with a 100px radius perfectly 🎯 centered inside the element. Anything outside that circle will be hidden.

    🔖 Note that setting the center it is the same as writing 50% 50%, maintain a cleaner and clearer code. ✨

    .circle {
      clip-path: circle(100px at center);
    }
                // OR //
    .circle {
    clip-path: circle(50% at center);
    }
    CSS
    A perfectlry centered circle with a 50% radius using clip-path

    Likewise, if we create a smaller circle.

    .circle {
      clip-path: circle(80px at center);
    }
                // OR //
    .circle {
    clip-path: circle(40% at center);
    }
    CSS
    A perfectlry centered circle with a 40% radius using clip-path

    clip-path: circle() VS border-radius

    Now, let’s see why we are utilizing the clip-path instead of simply relying on the border-radius CSS property. As we mentioned earlier, when setting the clip-path, we deal with two main values: the radius, similar to what border-radius offers, and the positioning, which is particularly important if we want to create a circle that is not 🎯 centered within the element.

    Let’s create our circle again, with a radius of 80px or 40% (depending on your preferences – if you use px or %). Next, position it, but not in the center of our element (50% 50%).

    🔶 If we want the visible part to be closer to the top side, we keep axis-X at 50%, but we change the axis-Y from 50% to 40%.
    🔶 If we want the visible part closer to the right side, we keep the axis-Y at 50%, but we will change the axis-X from 50% to 40%.

    .circle {
         // circle(radius at axis-X axis-Y) //
      clip-path: circle(80px at 50% 40%);
    }
                  // OR //
    .circle {
      clip-path: circle(40% at 50% 40%);
    }CSS
    CSS
    .circle {
       // circle(radius at axis-X axis-Y) //
      clip-path: circle(80px at 40% 50%);
    }
                  // OR //
    .circle {
      clip-path: circle(40% at 40% 50%);
    }CSS
    CSS
    A circle with a 40% radius using clip-path. It's center is placed at the top-left corner of the element
    A circle with a 40% radius using clip-path

    Setting clip-path instead of border-radius gives us the privilege to focus on any part of our element we prefer, not just the center. A really useful method, especially when working with images 📸 and you want to keep a part of the image that is not necessarily at the center.

    Let’s examine another case. What do you think? Are we able to vanish 🎩🐇 a whole piece of our circle and keep only a small part if needed? Let’s see the following code snippet. We position the center of the circle at zero (0%) on both axis. This means that the center of our circle will be placed at the top-left corner of the initial element, as that’s the point where both axes X and Y begin.

    .circle {
    clip-path: circle(80px at 0% 0%);
    }
                  // OR //
    .circle {
    clip-path: circle(40% at 0% 0%);
    }
    CSS

    Take a closer look at the image below. Since the circle is positioned at the element’s top-left corner, only the 🕞 quarter of the circle that fits within the element’s bounds will be visible, all the rest, that is extended beyond the element’s boundaries, will not be displayed at all. Cool hug! 😎

    Apply clip-path to images

    Now it’s the perfect time to analyze how we can utilize clip-path with images. A clever way to control their shape and also ‘cut out’ and leave in view only a specific part of the image.

    In the following example, we’re working with an image that contains four avatars, each placed in one of the image’s corners: top-left, top-right, bottom-left, and bottom-right. The image is divided into four equal parts, with one avatar in each. By using the clip-path: circle() function, we can focus on just one avatar at a time.

    An image with four avatars, each placed in one of the image's corners

    First, we apply clip-path: circle() to cut out the top-right part of the image, revealing only the avatar placed there. Then, we do the same for the top-left corner to show the avatar in that section. We repeat this process for the bottom-left and bottom-right parts as well, effectively isolating each avatar with a circular crop.

    Depending on the visual balance and spacing, you can choose 45% (blue 🔵 border) to match the exact size of the avatar or go with 50% (green 🟢 border) to include a bit of extra white space from the image background for a more relaxed look. 🌈 😎

    To target and isolate each avatar at the top of the image:

    🔶 For the top-right avatar, we place the circle’s center at 25% 25%. This moves the circle’s center closer to the top-right side of the image.

    🔶 For the top-left avatar, we set the position at 75% 25%. This turns the focus to the top-right area of the image.

    Adjusting these percentages gives you fine control over what part of the image stays visible, allowing you to highlight exactly what you want.

    .circle {
        // circle(radius at axis-X axis-Y) //
    clip-path: circle(45% at 25% 25%);
    }
                  // OR //
    .circle {
    clip-path: circle(50% at 25% 25%);
    }
    CSS
    .circle {
        // circle(radius at axis-X axis-Y) //
    clip-path: circle(45% at 75% 25%);
    }
                  // OR //
    .circle {
    clip-path: circle(50% at 75% 25%);
    }
    CSS
    An image with four avatars, each placed in one of the image's corners. Setting the clip-path: circle() we place the circle's center at 25% 25% and move  the circle's center closer to the top-right side of the image
    An image with four avatars, each placed in one of the image's corners. Setting the clip-path: circle() we place the circle's center at 75% 25% and move  the circle's center closer to the top-left side of the image

    Below we can see the final results for the two avatars. The first image displays only the first avatar while the second presents only the second one. All the rest of the avatars will be hidden. Pretty cool, right?

    Desplaying only the first avatar
    Desplaying only the second avatar

    This technique allows us to pinpoint and display specific parts of the image. Then, with the necessary positioning, we put this specific part of the image in our desired place. 😃 ✨

  • 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! 🌼

  • 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! 🌼

  • HTML for Blinking Text – Simple Copy & Paste Code

    If you’re here, chances are you’re looking for HTML for Blinking Text — maybe you remember the old-school <blink> tag that used to make text flash or flicker on screen. It looked something like this:

    <blink>This text will blink</blink>
    HTML

    Unfortunately (or fortunately, depending on your view), the <blink> tag is now considered obsolete and is no longer supported by modern browsers.

    Modern browsers no longer support <blink> because it was never officially standardized, causing serious accessibility issues. Visually impaired users, in particular, often rely on assistive technologies that don’t handle blinking content well. Plus, from a design standpoint, constant blinking can be distracting and overwhelming to users.

    Blinking Text Using HTML and CSS

    So how do you create blinking text today, in a way that’s clean, compliant, and works across all devices? That’s where HTML and CSS come in. With simple CSS animations powered by @keyframes, you can replicate the blinking effect — only better.

    <p class="blinking">This text will blink using CSS</p>
    HTML
    .blinking {
      animation: blink 1s step-start 0s infinite;
    }
    
    @keyframes blink {
      50% {
        opacity: 0;
      }
    }
    CSS

    This CSS-based method offers more flexibility than the old <blink> tag. You can control timing, opacity, color changes, or even trigger it on events like hover. Plus, it works across all modern browsers, making it a practical solution for attention-grabbing UI elements like warnings or notifications.

    You can even combine it with other effects like scaling or background changes for more dynamic visuals. Whether you’re building a retro-style webpage or emphasizing urgent content, this is a reliable, modern solution.

    Check this out in our codepen too

    See the Pen
    Blinking Text
    by Little Coding Things (@Little-Coding-Things)
    on CodePen.

    If you’re working on a project and still want that eye-catching flicker using CSS animation is the best and most future-proof way to implement HTML for Blinking Text. It’s responsive, accessible, and keeps your design up to today’s standards.

    Want to take it to the next level? Check out our post on creating a blinking eyes animation using CSS!

  • The CSS Text Shadow Property – Enhance Your Content

    The CSS Text Shadow Property – Enhance Your Content

    Hello everybody! In the land of web design, the CSS text shadow property is like adding magic to your text. It helps you create elegant headings that command attention and, many times, make text easier to read. The text-shadow empowers designers to pass beyond the limits of ordinary with just a few lines of simple yet powerful code.

    However, it’s essential to use it wisely, overdoing it can sometimes cause confusion and reading can end up difficult. Therefore, we must keep in mind that beyond styling, readability is also important. Always aim to strike a balance between appearance and clarity so our text is accessible to everyone.

    Text shadow structure

    First things first! We’ll begin with the structure and break down its components:

    • Offset-X and Offset-Y: They determine the horizontal and vertical distances of the shadow. When we use positive values, the shadow moves to the down and right. When we use negative values, the shadow moves to the top and left.
    • Blur-radius: It specifies the extent of blurring for the shadow. A higher value creates a spread, while a lower value sharpens the shadow.
    • Color: Here, we set the color of the shadow. All color methods are accessible (color names, hexadecimal codes, rgba and hsla values).

    If we don’t want to use a specific color, our shadow defaults to black.

    Below, I have prepared some examples to make this amazing tool more understandable. I’ll use the charming “Pacifico” font with the text “Text Shadow” to showcase its capabilities. So, let the game begin!! 😃

    Text shadow with positive values

    In our first example, we use positive values and create a gray shadow 5 pixels to the bottom and right of our text. It has a blur radius of 5 pixels, giving it a softened appearance.

    .text-shadow {
      text-shadow: 5px 5px 5px gray;
    }
    A shadow of 5px 5px 5px gray

    Text shadow with negative values

    Next, we create a gray shadow 5 pixels to the top and left of our text, using negative values. It has a blur radius of 5 pixels.

    .text-shadow {
      text-shadow: -5px -5px 5px gray;
    }
    A shadow of -5px -5px 5px gray

    Text shadow with colors

    Nothing better than playing with colors!! 🌈 In that case, we add two vibrant colors: magenta and cyan, then finish our shadow with color gray. Cool hug!? 😎
    As shown in the following code snippet, to create a repeating shadow with different colors, we must increase the pixels along both the X-axis and the Y-axis each time we add a new color.

    .text-shadow3 {
      text-shadow: 2px 2px 2px magenta, 4px 4px 2px cyan, 6px 6px 5px gray;
    }
    A shadow of 2px 2px 2px magenta, 4px 4px 2px cyan, 6px 6px 5px gray

    Text shadow with high blur-radius

    ⛔ In this example, we increase the blur, and we are able to notice that it is very, very important to keep blur-radius at low values, otherwise, our text appears a bit confusing with poor readability.

    .text-shadow4 {
      text-shadow: 5px 5px 20px gray;
    }
    Ashadow of 5px 5px 20px gray

    Text shadow with high values

    Finally, let’s get creative. By increasing the values at both the X-axis and Y-axis, we can widen the gap between the text and its shadow, achieving a more strongly marked visual effect.

    .text-shadow {
      text-shadow: 70px 50px 5px gray;
    }
    A shadow of 70px 50px 5px gray

    Whether a shadow type is “good” depends on your design goals. For bold, eye-catching text that stands on the page, this approach can be very effective. If you’re going for a more subtle or minimalistic design, you might opt for smaller offsets and blurs. It’s all about finding the balance that fits your overall design concept!

    Utilizing the text shadow, you are not only creating a stylish effect, but you are also crafting an experience that users will remember. So, get playful when using it. Experiment! Let your creativity shine through! ✨ 🎉

  • 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! 🌼

  • Made Easy With Reusable Code – Why Classes Matter

    Made Easy With Reusable Code – Why Classes Matter

    When building 🏗 websites, it’s common to create reusable code. What about you? Have you ever wanted to style multiple elements consistently without repeating yourself? That’s where CSS classes come in handy! They are flexible, well-structured, and designed to style multiple elements at once, giving them a consistent look. They assist you in reusing styles efficiently and also maintain your code organized and clean. 🧹 🧱

    Reusing styles with classes

    To highlight the value of reusable code with classes, consider the following simple example.

    Example
    Let’s say we want to create several buttons that all match in style and look uniform across the page.

    <button class="custom-button">Subscribe</button>
    <button class="custom-button">Submit</button>
    <button class="custom-button">Cancel</button>
    HTML
    .custom-button {
      width: 140px;
      height: 40px;
      font-size: 20px;
      font-weight: normal;
      color: black;
      background-color: e6e6e6; /* gray */
      text-align: center;
      border: none;
      border-radius: 8px;
      padding: 10px 20px;
      box-shadow: 4px 4px 10px 0 rgba(120, 120, 120, 0.4); /* semi-transparent gray */
      display: inline-block;
      cursor: pointer;
    }
    CSS

    As we can see below, all three buttons share the exact same characteristics by only sharing one class, the .custom-button. Whenever we want to restyle the buttons, we only need to make changes to this class, and the changes will take effect instantly on all buttons.
    Incredibly impressive but made easy at the same time! 😎

    Gray button with 'subscribe' written on.
    Gray button with 'submit' written on.
    Gray button with 'cancel

    The importance of keeping names precise and descriptive

    When creating class names, try to make them short yet meaningful. Do not use unclear and generic names. A name like .custom-button or .card-header gives a clear idea of what the class is for. Pick names that make sense at a glance. Descriptive names help you and others understand your code later, especially in larger projects.

    ✔ DO

    .profile-card {
      width: 250px;
      height: 250px;
      background-color: grey;
      border-radius: 50%;
    }
    CSS

    DON’T

    .card {
      width: 250px;
      height: 250px;
      background-color: grey;
      border-radius: 50%;
    }
    CSS

    Add Concise Comments

    Last but not least, always accompany classes with comments. Comment with precision. Your comments should clearly explain why you are using a particular approach rather than simply describing what the code does.
    Additionally, update comments as your code evolves. Outdated comments can be more harmful and misleading than having no comments at all. 😉

    Below, I have included an example.
    Remember, the correct way to declare a comment is:
    /* This is a comment in CSS */.

    CSS
    /* limit width to improve readability on large screens */
    .container {
      max-width: 1200px;
    }
    CSS

    Using reusable classes in CSS saves time and keeps your code well-organized and maintainable. So, next time you catch yourself repeating the same styles again and again, try grouping 🧲 them into a class!