Make a Fire Animation Text Effect With CSS

Creating a fire animation text effect with CSS is an imaginative way to bring dynamism to your content. Although it may not be the go-to choice for a conventional website, it reveals the creative potential of designing for the web. Let’s explore how we can set the text ablaze on your screen!

Kinsta

Crafting the Fire Animation Text Effect with CSS

Our first step is setting up the structure. Let’s breathe life into the phrase “Ignite your Design”. Here’s the HTML:


<div class="fire">Ignite your Design</div>

And now we’ll explore the corresponding CSS. We will apply a dark background for contrast, center-align the text, set the font and size, and apply a multi-layered text-shadow to give the text a fiery appearance:

body {
 background-color:#222; /* Setting dark background for visual contrast */
}

.fire {
 color: #f5f5f5; /* Light text color */
 text-align:center; /* Center alignment of text */
 font-family: 'Courier New', Courier, monospace; /* Monospace font */
 font-size: 80px; /* Text size */
 /* Multi-layered text-shadow for fire effect */
 text-shadow:
 0px -1px 3px #fff, /* Innermost layer - intense heat (white) */
 0px -2px 6px #FF3, /* Second layer - core of flame (yellow) */
 0px -6px 12px #F90, /* Middle layer - body of flame (orange) */
 0px -10px 20px #C33; /* Outermost layer - edges of flame (red) */
}

Let’s break this down further:

  • background-color:#222; – Sets the entire body’s background to a dark shade for contrast.
  • .fire – Targets the class of our element, which allows us to style our text.
  • color: #f5f5f5; – Sets the color of our text to a light grey for better visibility against the dark background.
  • text-align:center; – We align the text to the center of the page.
  • font-family: 'Courier New', Courier, monospace; – We define the font and chose a monospace font for its uniformity and simplicity.
  • font-size: 80px; – Sets the text size to be large and noticeable.
  • Crucially, the text-shadow property is where the magic happens. It creates multiple layers of shadows in different colors, which we perceive as a flame effect. The colors range from white (the hottest part of a flame) to red (the coolest), simulating a realistic flame gradient.

Bringing the Fire Animation to Life

Next, we’ll animate the text using the @keyframes rule to vary the text-shadow, creating a flickering fire effect:

/* Define the animation named "flicker" */
@keyframes flicker {
    /* Initial state of animation */
    0%, 
    /* Final state of animation */
    100% { 
        text-shadow: 
            0 -1px 3px #fff, /* Innermost layer - intense heat (white) */
            0 -2px 6px #FF3, /* Second layer - core of flame (yellow) */
            0 -6px 12px #F90, /* Middle layer - body of flame (orange) */
            0 -10px 20px #C33; /* Outermost layer - edges of flame (red) */
    }
    /* Middle state of animation */
    50% { 
        text-shadow: 
            0 -2px 6px #fff, /* Innermost layer - intense heat (white) */
            0 -4px 12px #FF3, /* Second layer - core of flame (yellow) */
            0 -8px 16px #F90, /* Middle layer - body of flame (orange) */
            0 -12px 24px #C33; /* Outermost layer - edges of flame (red) */
    }
}

.fire {
    /* Apply the "flicker" animation to the .fire class */
    animation: flicker 2s infinite;
}

Here’s the explanation:

  • @keyframes flicker – Here we declare the animation with the name “flicker”. Everything enclosed in the curly braces {} defines the progression of the animation.
  • 0%, 100% {...} and 50% {...} – These are the keyframes of the animation. They specify the state of the animation at specific points in time. At the start and end of the animation (0% and 100%), the text-shadow has a smaller blur radius, and in the middle (50%), the blur radius is larger. This variance gives the illusion of a flickering flame.
  • .fire { animation: flicker 2s infinite; } – This applies our animation to the .fire class. flicker is the name of the animation, 2s is the duration of one cycle, and infinite means it will repeat indefinitely.

See the Pen
Untitled
by 1stWebDesigner (@firstwebdesigner)
on CodePen.0

Fire Animation – More than Just Aesthetic Appeal

We’ve just conjured up a fire animation text effect using simple CSS!

However, our guide isn’t just about crafting a visually pleasing effect. It’s an educational journey into CSS’s dynamic features like text-shadow and @keyframes, showcasing their ability to create captivating visuals. The goal is to illustrate how simple lines of code can birth engaging visual effects.

Keep pushing boundaries and ignite your web design journey!

Engaging 3D Buttons with CSS

Interactive elements can elevate a website’s experience. Among these, the button is a crucial component, and when well-designed, it can potentially improve user engagement. 3D buttons, in particular, offer an attractive and tactile-like feel that can make your interface more dynamic and intuitive. In this tutorial, we’ll take you through the process of building an engaging 3D button using CSS.

Your Web Designer Toolbox

Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets Starting at only $16.50/month!

The Magic Behind 3D Buttons

What makes a button appear three-dimensional on a two-dimensional screen? The answer lies in the smart use of CSS properties and values. The depth, shadow, and interactive states of 3D buttons are meticulously crafted through CSS, creating a visual illusion of three-dimensionality. Let’s dive in and understand how this approach works.

Creating an Engaging 3D Button: A Step-by-Step Guide

We begin by defining the button structure using HTML:

<button class="btn3D">
  <span class="btnLayer">
    Click
  </span>
</button>

Here, we’ve designed a button with the class btn3D. Inside this button, we’ve placed a <span> element with the class btnLayer that encapsulates the text “Click”.

Now, let’s create the 3D effect with some CSS magic:

/* Style for the 3D button container */
.btn3D {
cursor: pointer; /* change cursor on hover */
padding: 0; /* remove default padding */
border: none; /* remove default button border */
border-radius: 14px; /* round button corners */
background: #AF3549; /* button color */
outline-offset: 3px; /* distance of outline from the button */
}

/* Style for the front layer of the 3D button */
.btnLayer {
display: block; /* make the span behave like a block element */
padding: 10px 40px; /* space around the text */
color: white; /* color of the text */
background: #FF4B59; /* color of the front layer */
font-size: 1.3rem; /* size of the button text */
border-radius: 14px; /* round the corners of the front layer */
transform: translateY(-5px); /* raise the front layer to create a 3D effect */
}

/* Style defining the button state during a click */
.btn3D:active .btnLayer {
transform: translateY(-3px); /* lower the front layer on click */
}

The .btn3D section focuses on initial button styling. We set the background to a rich red (#AF3549) and employ border-radius: 14px; for gentler, rounded edges. The default border is removed and padding is set to zero, ensuring a snug fit between the button border and its interior content. The cursor: pointer; changes the cursor to a hand when hovering, indicating a clickable element, while outline-offset: 3px; provides a small gap between the button and its focus outline, contributing to the 3D perception.

Moving on, the .btnLayer rules are essential for simulating depth. The internal span element is treated as a block (display: block;), letting us adjust margins and padding. Padding is then defined to allocate space around the text, influencing the button’s size.

We assign a vibrant red (#FF4B59) to the background, ensuring it stands out against the button’s base color, while the text color is white for better contrast. Matching the overall button aesthetics, font-size: 1.3rem; and border-radius: 14px; are set. Finally, to simulate depth, transform: translateY(-5px); nudges the span element up by 5 pixels.

Lastly, the .btn3D:active .btnLayer rule deals with the button’s reaction to a click. When activated, the span shifts down 2 pixels (transform: translateY(-3px);), simulating the button being pushed in and reinforcing the 3D experience.

Enhancing Your 3D Buttons

To further customize your 3D buttons, consider adjusting properties such as color, font size, and border-radius. Also, note that while properties like box-shadow and border can add appealing effects, they can negatively impact performance when animated. Therefore, for smooth transitions, focus on transform and opacity properties which are less performance-taxing.

Wrapping Up

Creating 3D buttons is more than an aesthetic venture; it’s about providing an intuitive and engaging interaction for your users. The tactile nature of 3D buttons can increase engagement, guiding users naturally toward taking the desired actions.

But remember, the best designs are those that strike a balance between visual appeal and usability. As exciting as it is to play around with different CSS properties to create eye-catching 3D buttons, don’t lose sight of functionality and accessibility. Always put your design to the test to ensure that it functions as good as it looks.

How to Animate a Progress Bar with CSS

Today, we’re exploring progress bars and their role in user interaction on websites. Progress bars provide users with visual cues for ongoing activities, such as page loading, file uploads, or form completions. In this tutorial, we’ll guide you through creating an animated, color-shifting progress bar using only CSS. This example not only demonstrates some capabilities of CSS but also serves as a foundation for further exploration and expansion. Let’s get started!

Kinsta

The HTML and CSS Setup

We start with a straightforward HTML structure: a parent <div> with the class progress-container that houses the overall progress bar, a progress <div> that styles the progress bar’s container and a child <div> with the class <progress-bar> which represents the advancing progress.

<div class="progress-container">
  <div class="progress progress-moving">
    <div class="progress-bar"></div>
  </div>
</div>

In the CSS, we’ll specify the appearance and behavior of these div elements. We’ll also detail the animation, governed by the progress-moving class, that visually communicates the progress.

/* The .progress-container is a wrapper around the progress bar that sets its overall width. */
.progress-container {
  width: 400px;
}

/* The .progress class sets the background, shadow, and border properties of the bar's container. */
.progress {
  padding: 6px; /* Adds space around the progress bar */
  border-radius: 30px; /* Rounds the corners of the bar's container */
  background: rgba(0, 0, 0, 0.25); /* Sets a semi-transparent black background */
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08); /* Adds inner shadow for 3D effect and slight outer highlight */
}

/* The .progress-bar class defines the appearance and the animation behavior of the actual progress bar. */
.progress-bar {
  height: 18px; /* Sets the height of the progress bar */
  border-radius: 30px; /* Ensures the progress bar has rounded corners */
  background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05)); /* Adds a subtle gradient to the progress bar */
  transition: 0.4s linear; /* Smoothens the transition when properties change */
  transition-property: width, background-color; /* Specifies which properties the transition effect applies to */
}

/* The .progress-moving .progress-bar selector applies when the progress bar is moving. */
.progress-moving .progress-bar {
  width: 85%; /* Sets the final width the progress bar should reach */
  background-color: #EF476F; /* Sets the final color the bar should transition to */
  animation: progressAnimation 6s; /* Specifies the animation that will play */
}

/* Defines the start and end states of the progress bar during the animation. */
@keyframes progressAnimation {
  0%   { width: 5%; background-color: #F9BCCA; } /* The progress bar starts at 5% width and a light pink color */
  100% { width: 85%; background-color: #EF476F; } /* It ends at 85% width and a darker pink color */
}

In our setup, the progress bar is housed in a .progress-container, which controls the overall width of the progress bar. The .progress class gives styling to the progress bar’s container, adding padding, a rounded border, a semi-transparent black background, and a subtle shadow effect for depth.

  • The .progress-bar class defines the visual characteristics and animation behavior of the progress bar itself. Its height, rounded corners, and background gradient are set, and it uses the transition property to ensure that changes in width and background color occur smoothly over time.
  • The .progress-moving .progress-bar selector is used to specify the animation when the progress bar is in motion. This is where the final width and color of the progress bar are set, along with the details of the animation that will play.
  • The @keyframes progressAnimation rule specifies the start and end states of the progress bar during the animation. At the start (0%), the progress bar has a width of 5% and a light pink color (#F9BCCA). At the end (100%), the progress bar expands to 85% of its container width and changes to a darker pink color (#EF476F).

Potential Improvements

In addition, here are some areas to consider for augmenting the progress bar:

  • Dimensions: Adjusting the progress bar’s dimensions to harmonize with your page’s other elements can help enhance your user interface’s overall aesthetics. Ensuring the progress bar is not disproportionately large or small is crucial for maintaining a balanced display.
  • Design Coherence: Aligning the progress bar’s visual elements, such as color and animation, with your website’s overall design can enhance the consistency of your user interface.
  • Device Compatibility: Guaranteeing your progress bar’s functional and visual consistency across various devices and screen sizes is vital. This will cater to users regardless of their device preferences.

Final Thoughts

While we discussed the standalone design in this guide, such progress bars are typically paired with JavaScript to reflect real-time changes in data, enhancing user interaction further. The techniques shown here can also serve as a base for creating other interactive components on your site. We’ve only scratched the surface of what’s possible with CSS animations. We encourage you to explore, experiment, and create with your newfound knowledge!

Tooltips with a Retro Gaming-Inspired Design

Today, we’ll delve into a creating tooltip with a retro gaming-inspired design that could add an interactive, fun touch to your interface. This guide will walk you through the setup needed to craft this unique tooltip and explain each step in detail. As a result, we’ll have a tooltip with a gaming-style font, harmonious colors, and smooth animations. Let’s dive in.

Kinsta

The HTML Structure

Let’s start with the structure. Our journey begins with HTML. This is where we craft the skeleton of our tooltip, using a simple button with an embedded span tag. The button triggers the tooltip, and the span tag houses the tooltip text:

<button>Hover Over Me
    <span>Hey! A retro gaming-style tooltip.</span>
</button>

CSS Styling

Next, we move on to the CSS styling, the core of our tooltip’s appearance and animation. Our CSS styling is broken down into four stages: General Setup, Button Styling, Tooltip Styling, and Tooltip Animation.

General Setup

/* Importing custom font for retro gaming feel */
@import url("https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap");

body {
  /* Centring the button */
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

We import a custom gaming-style font Press Start 2P from Google Fonts for a retro gaming look. Then we style the body to center our button.

Button Styling

button {
  /* Making the button interactive and center aligned */
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;

  /* Styling the button */
  width: 16em;
  height: 3.2em;
  padding: 0 1em;
  border: none;
  border-radius: 3px;
  background-color: #f04e23;
  color: #fff;

  /* Applying custom font */
  font-family: "Press Start 2P", cursive;
  font-size: 1.8vw;

  cursor: pointer;
  outline: none;
  appearance: none;
}

We start by setting the button to flex and aligning the items to the center. The button is given a width and height, padding, and styled with a rounded border. We set the background color to red-orange (#f04e23), the text color to white, and apply the custom font. The cursor is set to pointer to indicate the button is interactive.

Tooltip Styling

span {
  /* Positioning tooltip relative to the button */
  position: absolute;
  left: 50%;
  bottom: 100%;
  opacity: 0; /* Initially hiding the tooltip */
  margin-bottom: 1em;
  padding: 1em;

  /* Styling tooltip */
  background-color: #303030;
  font-size: 0.6em;
  line-height: 1.6;
  text-align: left;
  white-space: nowrap;

  /* Setting initial state for animation */
  transform: translate(-50%, 1em);

  /* Making the changes smooth for animation */
  transition: all 0.15s ease-in-out;
}

span::before {
  /* Creating a triangle at the top of tooltip */
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 0;
  height: 0;
  border: 0.5em solid transparent;
  border-top-color: #303030;
  transform: translate(-50%, 0);
}

The span, which contains the tooltip text, is given an absolute position to enable it to be positioned relative to the button. The tooltip is hidden initially with opacity: 0;. The tooltip color is set to dark gray (#303030) to contrast with the button. The span::before selector is used to create a triangle at the top of the tooltip.

Tooltip Animation

button:hover span {
  /* Making tooltip visible and moving it upwards */
  opacity: 1;
  transform: translate(-50%, 0);
}

When the button is hovered over, the tooltip’s opacity changes to 1, making it visible. The transform property also changes; it shifts the position of the tooltip from its initial state (1em below the button, out of sight) to a new state (aligned with the bottom of the button, but appearing above it because of the absolute positioning). The transition property that we defined in the Tooltip Styling section ensures these changes occur smoothly over time, creating an engaging animation effect.

And that’s it! This should give you a button with a cool retro gaming-themed tooltip.

You can play around with the text, colors, font sizes, and other parameters to customize the look and feel of your tooltips to match your taste and preference.

The Final Result

 

an orange retro looking tooltip

While this retro gaming-style tooltip is a fun addition, remember that it’s not an industry standard. However, it could prove great for personal websites or projects that allow for a more creative and playful interface. You should also consider the color contrast for visually impaired users and the tooltip’s mobile compatibility.

 

Colorful World: Gradient Backgrounds in CSS

Gradients—a seamless transition of colors—are a powerful visual tool that can transform a plain background into a dynamic digital landscape. With CSS, you can create linear, radial, conic, and repeating gradients, each offering unique ways to infuse depth and vibrancy into web pages. This guide will primarily focus on the most widely used types: linear and radial gradients. Let’s delve into the versatile world of CSS gradient backgrounds and uncover their possibilities.

Kinsta

Understanding Linear and Radial Gradients

To craft visually striking gradient backgrounds, you need to grasp two core types that CSS offers – linear and radial gradients. These form the bedrock for crafting complex and stunning color transitions.

Dawn Inspiration with Linear Gradients

Creating a gradient that mirrors the mesmerizing hues of sunrise is quite straightforward with CSS linear gradients.

body {
    background: linear-gradient(to right, #ff7e5f, #feb47b);
}

In this code snippet, the gradient starts with a warm, pinkish hue (#ff7e5f), slowly transitioning to a brighter, sun-touched tone (#feb47b). The phrase ‘to right’ defines the direction of the gradient flow, leading to a seamless left-to-right color transition.

Sky Aesthetics with Radial Gradients

Radial gradients can be used to emulate the vastness of a clear blue sky. Here’s an example:

body {
    background: radial-gradient(circle, #3e92cc, #070d59);
}

This radial gradient creates a circular pattern that transitions from a bright blue (#3e92cc) at the center to a deep night blue (#070d59) at the edges, resulting in a sky-like visual effect.

Exploring the Rainbow with Linear Gradients

A sound understanding of linear and radial gradients allows for exploration into slightly more complex color transitions. Let’s demonstrate this by creating a CSS linear gradient that transitions through the vibrant spectrum of a rainbow.

body {
  background: linear-gradient(
    90deg,
    red,
    orange,
    yellow,
    green,
    blue,
    indigo,
    violet
  );
}

The code above generates a vivid rainbow gradient starting with red on the far left, flowing through the colors of the spectrum, and concluding with violet on the far right. The 90deg directive indicates the gradient transition’s direction.

Wrapping Up

While the examples presented only scratch the surface of gradients’ potential, they serve as a springboard for further experimentation. Don’t be afraid to mix colors, shift directions, or change gradient types to discover unique and captivating designs. CSS gradients also allow advanced control over the gradient process by using color stops, and other values like percentages or pixels, to fine-tune the color transition’s position and range. When strategically employed, they can accentuate specific sections of a webpage, such as a call-to-action button or a promotional banner, effectively drawing user attention.

Neon Glow Text: A CSS Showcase

Web design provides a canvas where technological precision and creativity converge. In this exploration, we’ll be embarking more on the creative side, unmasking an exciting feature of CSS – the neon glow text effect. This visually appealing trick is a delightful experiment with the capabilities of CSS.

Kinsta

Constructing Neon Glow Text with CSS

In this section, we’ll illuminate how CSS can generate a neon glow text effect. We’re going to incorporate the Monoton font from Google Fonts. By using CSS text-shadow, we’ll create our neon glow, and add a sprinkle of animation for that flickering neon allure.

/* Import Monoton font from Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Monoton&display=swap');

body {
    /* Create a dark background to enhance the neon effect */
    background-color: #000;
}

.neon {
    /* Apply the Monoton font and set color to white */
    font-family: 'Monoton', cursive;
    font-size: 70px;
    color: #ffffff;

    /* Create the neon effect using multiple text shadows */
    text-shadow:
        0 0 10px #ff4da6,
        0 0 20px #ff4da6,
        0 0 30px #ff4da6,
        0 0 40px #ff4da6;

    /* Add a glow animation for a flickering effect */
    animation: glow 1s infinite alternate;
}

/* Define the glow animation */
@keyframes glow {
    from {
        text-shadow:
            0 0 10px #ff4da6,
            0 0 20px #ff4da6,
            0 0 30px #ff4da6,
            0 0 40px #ff4da6;
    }
    to {
        text-shadow:
            0 0 20px #ff4da6,
            0 0 30px #ff4da6,
            0 0 40px #ff4da6,
            0 0 50px #ff4da6,
            0 0 60px #ff4da6;
    }
}

The text-shadow property acts as our magic tool here, infusing a radiant glow to the text. We stack multiple shadows with varying blur radii to build the glowing aura. The animation property adds dynamic behavior to our text, mimicking a flickering neon sign.

We’re going to add this to the corresponding HTML:

<h1 class="neon">Neon Glow</h1>

Beyond the Showcase: Practical Applications

The neon glow text effect, while not a staple in traditional web design, opens up an array of intriguing possibilities. For instance, imagine infusing a bit of vibrancy into HTTP response status messages or error pages. A 404 error page with a neon, flickering glow could turn a frustrating user experience into an amusing one.

Similarly, you could use this effect to emphasize promotional elements on a website. A neon glow effect announcing a limited-time discount might serve as a unique attention-grabber.

Wrapping Up

CSS can be an immensely powerful tool in a web designer’s arsenal, offering numerous possibilities to let creativity shine. Our demonstration is a testament to that, a creative possibility where a simple text gets a vibrant, retro makeover. We encourage you to keep exploring and experimenting, for every line of code holds the potential to make your designs distinct and memorable.

Creating Engaging Hover Effects with SCSS

SCSS is a powerful syntax of Sass that extends the capabilities of CSS, making it easier to create dynamic and customizable styles. To see this in action, we’ll demonstrate how to create a neat hover effect, which gives an appearance of being filled when hovered over. We’ll explain the implementation process, and customization options while providing context for the SCSS code.

Your Web Designer Toolbox
Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets


The HTML Structure

Before diving into the SCSS magic, let’s start by defining a simple HTML structure for our button.

<div class="buttons">
  <h1>
    Simple hover effects with <code>box-shadow</code>
  </h1>
  <button class="fill"> Fill In</button>
</div>

In this snippet, we have a button element with a class of fill. This class will be used in our SCSS to define the hover effect.

Crafting the Hover Effect with SCSS

Now, let’s delve into the SCSS code and shed light on the key parts of our hover effect. Here, we apply various SCSS rules and CSS custom properties to create an engaging visual effect.

/* Base styling for the button */
button {
  --color: #a972cb; /* Button color */
  --hover: #ef6eae; /* Hover color */
  color: var(--color); /* Applying the color */
  background: none;
  border: 2px solid var(--color); /* Border with the color of the button */
  font: inherit;
  line-height: 1;
  margin: 0.5em;
  padding: 1em 2em;
  transition: 0.25s; /* Transition time */
}

/* Styling for button hover/focus state */
button:hover,
button:focus {
  color: #fff; /* White text on hover */
  border-color: var(--hover); /* Border color change on hover */
  box-shadow: inset 0 0 0 2em var(--hover); /* Inset box-shadow to create a fill effect */
}

The button selector defines the default styles for our button. We use CSS custom properties (--color and --hover) to set the color scheme for our button and its hover state. The transition property allows us to animate changes to these properties, creating a smooth fill effect on hover.

On hover or focus, we update the button’s text color, border-color, and apply an inset box-shadow to mimic the fill effect. This change is animated over 0.25 seconds as specified by the transition property in the button selector.

Rounding Up with Page Styling

For a better visual demonstration, we add some page styling. However, remember that these styles are tailored to this specific example, and in a real-world scenario, they should be adjusted according to suit your needs.

/* Page styling */
body {
  color: #fff;
  background: hsl(227, 10%, 10%);
  font: 300 1em 'Fira Sans', sans-serif;
  justify-content: center;
  align-content: center;
  align-items: center;
  text-align: center;
  min-height: 100vh;
  display: flex;
}

/* Heading styling */
h1 {
  font-weight: 400;
}

The body selector styles include the webpage’s font, text alignment, and color scheme. The h1 selector sets the font weight for the title.

Now, when the “Fill in” button is hovered over, we’ll see the effect in action.
button and text with effect when hovered over

 

Adapting this hover effect to suit your site’s aesthetic is as straightforward as modifying the --color and --hover CSS variables. Don’t forget to consider accessibility principles when choosing your color scheme, as the contrast between the button color and background color is important for readability. Rounded corners, set by the border-radius property, have been increasingly trendy and also contribute to better user experience due to their softer visual impact.

Styling Input Fields using CSS :placeholder-shown

In web development, it’s often the small touches that enhance the user experience and make your website stand out. The :placeholder-shown pseudo-class in CSS selects input elements when their placeholder text is visible, offering a convenient way to distinguish between empty fields and those that contain user input. This allows you to create dynamic styling and improve the user experience by providing visual feedback.

Consider this concise example, where we apply a subtle effect to empty input fields.

Your Designer Toolbox Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets

Constructing the Form

We’ll start by setting up the HTML structure for our form. Each input field includes a placeholder text and is assigned a class called .highlight-empty.

<form>
  <input type="text" placeholder="Enter your name" class="highlight-empty">
  <input type="email" placeholder="Enter your email" class="highlight-empty">
</form>

Applying Styles with CSS

Once we’ve established our form structure, we can move on to styling our input fields where the use of the :placeholder-shown pseudo-class is critical.

input {
  font-size: 0.9rem;
  margin: 10px;
  padding: 5px;
  width: 20%
}

.highlight-empty:placeholder-shown {
  border: 2px solid lightcoral;
  box-shadow: 0 0 5px lightcoral;
}

html, body {
  background: #333;
}

body {
  padding-top: 4em;
}

form {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

Understanding the CSS Code

In the CSS code above, we’ve used the :placeholder-shown pseudo-class to apply a light coral border and a subtle glow to the input fields when they are empty and show the placeholder text. As soon as the user starts typing, the effect disappears, indicating that the input has been provided.

.highlight-empty:placeholder-shown {
  border: 2px solid lightcoral; /* Adds a light coral border to empty fields */
  box-shadow: 0 0 5px lightcoral; /* Adds a subtle glow to empty fields */
}

Other CSS properties applied include the styling of input fields (input), the styling of the body (body), and the arrangement of form elements (form). However, you’ll likely work within more complex structures. For instance, you might apply the input styles within specific form components instead of universally. Similarly, the form styles here are rudimentary. They’d usually be adjusted to match your website’s layout and design requirements.

Exploring the Final Result

Check out the GIF below to see the result of this code in action.

input fileds

To customize further, you can experiment with different border styles, colors, and box-shadow properties. In addition, you can combine :placeholder-shown with other CSS selectors, such as :not, to create effects for different input states.

💡Pro Tip: Note that :placeholder-shown selects the input itself, while ::placeholder styles the text. As a result, the styling of the placeholder text might be affected due to its parent-element relationship.

Beautiful Blockquotes with CSS ::before Pseudo-Element

Today, we’ll explore how to design blockquotes using the CSS ::before pseudo-element. This straightforward yet versatile element allows designers to add styling or insert content before an element’s main text, without modifying the HTML markup. Let’s see how you can combine it with other CSS properties to create visually appealing blockquotes that can enhance your web content.

Your Web Designer Toolbox
Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets


Implementing the Blockquotes

We’ll start by setting up our HTML structure. We will use the blockquote HTML element, styled with a CSS class named .custom-blockquote.

<blockquote class="custom-blockquote">
  Creativity involves breaking out of established patterns to look at things in
  a different way.
  <span>Don Norman</span>
</blockquote>

Once we have our structure set up, let’s move on to the CSS. The ::before pseudo-element will play a key role in adding a unique design element to our blockquote.

@import url('https://fonts.googleapis.com/css?family=Open+Sans:400italic,700');</pre>
.custom-blockquote {
font-size: 1.4em;
width: 60%;
margin: 50px auto;
font-family: Open Sans, sans-serif;
font-style: italic;
color: #555555;
padding: 1.2em 30px 1.2em 75px;
border-left: 8px solid #FFA07A;
line-height: 1.6;
position: relative;
background: #EDEDED;
}

.custom-blockquote::before {
content: "\201C";
color: #FFA07A;
font-size: 4em;
position: absolute;
left: 10px;
top: -10px;
font-family: Arial, sans-serif;
}

.custom-blockquote span {
display: block;
color: #333333;
font-style: normal;
font-weight: bold;
margin-top: 1em;
}

Understanding the Key Aspects

Our CSS code incorporates various elements to enhance the design of our blockquote. Here’s an explanation of the crucial aspects:

  • The ::before pseudo-element: This element adds a large, stylized opening quotation mark before the blockquote’s text. We set its font-family to Arial to create a distinct look. The content property is used to insert the quotation mark, and the color property is set to #FFA07A, matching the color of the blockquote’s left border.

.custom-blockquote::before {
content: "\201C"; /* Inserts the opening quotation mark */
color: #FFA07A; /* Matches the color of the left border */
font-size: 4em; /* Sets the size of the quotation mark */
position: absolute; /* Positions the quotation mark relative to the blockquote */
left: 10px; top: -10px; /* Adjusts the position of the quotation mark */
font-family: Arial, sans-serif; /* Sets the font for a unique look */
}

  • The .custom-blockquote class: This class includes multiple properties that design and position our blockquote. We set the font-family to Open Sans for the quote and the author’s name, using italic and bold variations for distinction.

.custom-blockquote {
font-size: 1.4em; /* Sets the font size for the quote and the author's name */
width: 60%; /* Adjusts the width of the blockquote */
margin: 50px auto; /* Centers the blockquote and adds margin on the top and bottom */
font-family: Open Sans, sans-serif; /* Sets the font for the quote and author's name */
font-style: italic; /* Applies italic style to the quote */
color: #555555; /* Sets the color for the quote */
padding: 1.2em 30px 1.2em 75px; /* Adds space around the quote and author's name */
border-left: 8px solid #FFA07A; /* Adds a left border with a unique color */
line-height: 1.6; /* Improves the readability of the quote */
position: relative; /* Sets the position relative to the parent element */
background: #EDEDED; /* Sets a light grey background color */
}

The Final Design

The image below showcases the final result of the implementation. You’ll see that the creative use of CSS ::before pseudo-element and other design properties result in an attractive, distinct blockquote that stands out from regular web content.

blockquote with quotation inside it

Remember, while this guide provides a specific styling, you can freely modify the color, font, size, positioning, and other properties to match your website’s design language. We encourage you to do so!

The Role of Social Proof in Web Design

Social proof is the psychological phenomenon where individuals follow the actions of others, believing that those actions represent the correct behavior.

Think about the long lines outside an Apple Store during a product launch. Those lines make us believe that the product is valuable and desirable because so many people want it. The same concept applies to the web where social proof can take various forms.

Your Web Designer Toolbox

Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets Starting at only $16.50/month!

Harnessing the Power of User Testimonials and Reviews

Trust is intangible, yet it can make or break the relationship with your users.

One of the most compelling forms of social proof comes from testimonials. When potential customers see positive statements from those who have used your product or service, it helps ease their decision-making process. These endorsements act as assurances of your product’s value.

In addition to testimonials, other user’s reviews, and ratings can greatly influence prospective customers. Collective user feedback often offers an unbiased perspective on your offerings, making potential customers feel more confident about their purchase decisions.stars lined up diagonally

Boosting Your Online Credibility with Endorsements and Affiliations

An endorsement from a reputable figure in your industry can significantly bolster your brand’s credibility. Such approvals validate your offerings and can set you apart in a crowded market. Your alliances also reflect your credibility. Displaying logos of esteemed clients or partners you’ve worked with can subtly yet effectively boost your brand’s trustworthiness.

hand gestures

Showcasing Popularity and Expertise

Your social media presence can reflect your brand’s popularity. Showcasing follower counts, likes, or shares illustrates your brand’s reach and influence. Your accolades and certifications showcase your commitment to excellence in your industry. These badges of honor provide further assurance of your expertise.

brand logos

Leveraging Social Proof Strategically

Successful implementation of social proof requires careful planning and execution. Every audience is different, and the types of social proof that resonate can vary greatly. It’s crucial to identify what appeals most to your target demographic. For maximum impact, social proof elements should be placed in high-visibility areas on your website, such as landing or product pages.

Always prioritize genuine content, especially when it comes to user testimonials and reviews. Authenticity not only upholds ethical standards but also strengthens your brand credibility. Affiliations with authoritative figures or organizations in your industry are a testament to your brand’s credibility and should be prominently featured.planing designs in front of a PC

Final Thoughts

Social proof, when used right, can turn a skeptic into a believer. It’s more than just showing potential customers that others approve of your product or service. It’s about strategically showcasing that your offerings are trusted, credible, and desirable—thereby nudging users to follow suit. Remember, you can also employ tactics such as time-limited offers, exclusive content, or highlighting limited stock. After all, when users see others seizing an opportunity, they feel the urge to jump on the bandwagon.

How to Toggle Between Classes with JavaScript

Today, we’re exploring a simple yet effective technique for toggling CSS classes on an HTML element using JavaScript. We’ll demonstrate this on a button element, and highlight the control of the visual appearance and state with just a few lines of code.

Your Web Designer Toolbox
Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets


Creating the HTML Button


<button id="button" class="red">STOP</button>

We initiate our demo with a button element identified by the id “button” and carrying an initial class of red.

Styling the Button with CSS


body {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: grey;
}

button {
padding: 10px;
font-size: 1.1em;
border: none;
border-radius: 10px;
border: 1px solid rgba(0, 0, 0, 0.2);
cursor: pointer;
}

.green {
background: green;
color: white;
}

.red {
background: red;
color: white;
}

The CSS above does two things: it improves the button’s appearance and it defines two state classes – .green and .red. These classes will be alternated in JavaScript, affecting the button’s color and the associated user message.

Toggling with JavaScript


const button = document.getElementById("button");
const buttonPressed = (e) => {
e.target.classList.toggle("green");
e.target.classList.toggle("red");
e.target.innerText = e.target.innerText.trim() === "STOP" ? "GO" : "STOP";
};
button.addEventListener("click", buttonPressed);

In the JavaScript snippet, we first access the button element using its id, "button". The buttonPressed function is then defined to react to a click event on this button. With each click, the .green and .red classes are toggled on our button element using classList.toggle(). This gives us the visual interplay between the red and green states.

Moreover, the button’s text also toggles between “STOP” and “GO” thanks to a ternary operator. This operator checks if the current button’s text is “STOP”, changing it to “GO” if true, and if not, it reverts back to “STOP”. This creates a clear visual correlation between the button’s appearance and its stated status.

The Final Result

 

alternating stop and go button

 

💡 Pro Tip: The power of class toggling extends beyond our demonstration. You can create rich, interactive experiences across your designs by applying this technique. Consider a photo gallery where toggling a class alters the layout view, or a “Read More” feature on blog excerpts that expands the content view. The concept could also be applied to toggle dark and light modes on a website, offering a customizable user experience.

CSS Pseudo-Class :indeterminate – A Practical Guide

The CSS pseudo-class :indeterminate is a handy tool that can add a layer of sophistication to user interface interactions. Primarily, it helps to indicate an intermediate state in UI elements, such as a checkbox, when a user’s selection is partially complete. So, let’s examine a straightforward example that showcases the potential application of this feature.

Your Web Designer Toolbox
Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets


Setting Up the HTML Structure

<div class="container">
  <ul>
    <li>
      <input type="checkbox" id="category">
      <label for="category">
        Groceries
      </label>
      <ul>
        <li>
          <label>
            <input type="checkbox" class="subCategory">
            Fruits
          </label>
        </li>
        <li>
          <label>
            <input type="checkbox" class="subCategory">
            Vegetables
          </label>
        </li>
        <li>
          <label>
            <input type="checkbox" class="subCategory">
            Dairy
          </label>
        </li>
      </ul>
    </li>
  </ul>
</div>

In this scenario, we’ve structured a list with a main checkbox labeled “Groceries” and three sub-categories.

Enhancing Visual Feedback with CSS

Next, we focus on using CSS to visually distinguish between various states of our checkboxes.

body {
color: #555;
font-size: 1.25em;
font-family: system-ui;
}

ul {
list-style: none;
}

.container {
margin: 40px auto;
max-width: 700px;
}

li {
margin-top: 1em;
}

label {
font-weight: bold;
}

input[type="checkbox"]:indeterminate + label {
color: #f39c12;
}

The input[type="checkbox"]:indeterminate + label selector is key here. It targets the label of the main checkbox when it’s in the indeterminate state, changing its color to indicate partial selection. The rest of the CSS provides general aesthetic tweaks.

Introducing Interactivity with JavaScript

const checkAll = document.getElementById('category');
const checkboxes = document.querySelectorAll('input.subCategory');

checkboxes.forEach(checkbox = >{
  checkbox.addEventListener('click', () = >{
    const checkedCount = document.querySelectorAll('input.subCategory:checked').length;

    checkAll.checked = checkedCount > 0;
    checkAll.indeterminate = checkedCount > 0 && checkedCount < checkboxes.length;
  });
});

checkAll.addEventListener('click', () = >{
  checkboxes.forEach(checkbox = >{
    checkbox.checked = checkAll.checked;
  });
});

The JavaScript code here manages the state of the main checkbox based on the sub-options selected. The main checkbox enters an intermediate state, displaying a horizontal line as styled by Chrome on Windows when some sub-options are chosen. When all the sub-options are checked, the main checkbox returns to its original color and enters the checked state.

The Final Result

As each grocery item is selected, the main “Groceries” checkbox alternates between states, reflecting the selection status of the sub-items. This creates a clear visual cue to the user about the selection status.

checklist checking

Our demonstration through this HTML, CSS, and JavaScript blend, is just one of many tools you can use to enhance UI clarity. Don’t stop here—consider how other CSS pseudo-classes like :hover, :focus, or :active can also be utilized to provide real-time feedback to users. As you expand your web design toolkit, remember the goal is to create user experiences that are not only visually appealing but also communicate effectively with your audience.

5 Chrome Extensions Every Web Designer Should Try

Web designers are continually on the lookout for tools that improve their workflow and productivity. For that reason, we’re highlighting five essential Chrome extensions, covering various aspects such as website analysis, performance optimization, and accessibility. Let’s dive in.

Your Web Designer Toolbox

Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets Starting at only $16.50/month!

Wappalyzer

Wappalyzer is an indispensable extension that identifies the technologies used on any website. With just a click, you can get detailed insights into the frameworks, libraries, content management systems, and more, providing valuable context when troubleshooting or researching new projects.

Lighthouse

Developed by Google, Lighthouse is a powerful tool for checking a website’s performance, accessibility, and SEO. With this extension, you can quickly generate reports that provide actionable recommendations to improve your site’s overall quality and user experience, ensuring that your project adheres to best practices.

Web Developer

The Web Developer extension equips your browser with a plethora of web design-related tools. It offers various features including DOM manipulation and CSS inspection to form control and responsive design testing. While it may seem more oriented towards developers, as a designer, understanding and using these features can facilitate a healthy collaboration with the development team.

CSSViewer

CSSViewer is a simple yet handy Chrome extension that allows you to inspect the CSS properties of any page element. By hovering over the desired element, you can instantly view its dimensions, fonts, colors, and other CSS properties, making it easier to debug and refine your designs.

Axe

The Axe extension assists in auditing your website for accessibility issues and offers practical guidance on addressing them. This tool is designed to eliminate false positive results, saving you time by focusing on genuine issues.

Bonus Pro Tip

For an additional productivity boost, consider using a Chrome extension like Tab Wrangler to automatically manage and close inactive tabs, reducing clutter and freeing up valuable system resources during your development sessions.