Create Neon Style Buttons Using CSS

CSS truly is a remarkable tool in a web designer’s toolkit, capable of bringing even the most vibrant creative visions to life. Today, we’re immersing ourselves in the radiant world of neon style buttons, showcasing the impressive spectrum of CSS capabilities. Ready to set your CSS knowledge aglow? Let’s get started!

Your Web Designer Toolbox

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

HTML: Building the Neon Button

Our HTML structure for the neon button is quite straightforward:

<button class="neon-button">NEON</button>

We’ve just set up a button with the class “neon-button” which we’ll use to apply our CSS styles.

CSS: Crafting the Neon Glow

Let’s now dive into the CSS code to give our button that neon look:

/* Load custom font from Google Fonts */
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@700&display=swap");

body {
  background-color: #1a1a1a; /* Dark background for neon contrast */
}

/* Styling for our neon button */
.neon-button {
  color: #ff4b59; /* Text color */
  background-color: #1a1a1a; /* Same as the background for a seamless look */
  border: 4px solid #ff4b59; /* Solid border with neon color */
  border-radius: 10px; /* Slight rounding of corners */
  padding: 15px 30px; /* Padding around the text */
  font-size: 25px; /* Visible and impactful text size */
  font-family: "Montserrat", sans-serif; /* Stylish font */
  letter-spacing: 3px; /* Space between letters for better readability */
  cursor: pointer; /* Changes cursor to a pointer on hover */
  font-weight: bold; /* Bold text */
  filter: drop-shadow(0 0 10px #ff4b59) drop-shadow(0 0 30px #ff4b59)
    contrast(1.8) brightness(1.8); /* Adds a subtle glow effect and enhances the vibrancy */
  transition: 0.5s; /* Smooth color change on hover */
}

/* Styling for hover state */
.neon-button:hover {
  color: #1a1a1a; /* Text color changes on hover */
  background-color: #ff4b59; /* Button color fills on hover */
  filter: drop-shadow(0 0 10px #ff4b59) drop-shadow(0 0 40px #ff4b59)
    contrast(1.8) brightness(1.8); /* Glow effect is enhanced on hover */
}

Let’s break down this CSS snippet:

  • Color & Background: We use color to set the text color to #FF4B59, our chosen neon shade. The background-color is set to #1A1A1A, which is a dark tone to enhance the neon glow.
  • Border & Border Radius: We have border set to 4px and the same color as our text to give our button a neon border. The border-radius property is used to give the button slightly rounded corners.
  • Font Size & Family: font-size is set to 25px to ensure our text is large enough to be impactful, and font-family is set to ‘Montserrat’, a stylish sans-serif font, to give our text an appealing look.
  • Letter Spacing & Font Weight: We used letter-spacing to provide some space between letters for better readability, and font-weight is set to bold for more emphasis.
  • Filter & Transition: The filter property is employed to apply the drop-shadow function twice to create a glowing effect around the text and the border. This glow effect intensifies upon hovering. The transition property ensures a smooth transformation of colors when the button is hovered over.

The Result

See the Pen
Neon Style Button
by 1stWebDesigner (@firstwebdesigner)
on CodePen.0

Final Thoughts

This approach provides a straightforward way to create a neon-style button. However, it’s only one of many possible techniques.

In the broader scope of CSS, there are numerous ways to enhance this effect. For instance, using transform property for animated scaling effects, controlling opacity for more depth, using CSS variables for easier management of values, and leveraging pseudo-elements like :before and :after for more complex effects.

If the neon button is meant to serve as a link, it might be more semantically appropriate and beneficial for SEO to use an <a> element instead of a <button>.

Also, to make designs more responsive, consider using relative units like em or rem instead of px, which allows for more fluid scaling across different screen sizes.

Playing around with different box-shadow values can lead to different glow intensities and spread. Combining all these methods can yield an even more impressive and dynamic neon button.

Don’t hesitate to take what you’ve learned here and push it a step further. CSS is full of such opportunities for those willing to explore!

CSS Keyframes: From Static to Dynamic Designs

Web designers often seek tools that can bring static elements to life, and CSS keyframes are a great ally for this task. Keyframes enable us to animate elements over a certain duration, providing our designs with a dynamic feel. Below, we’ll cover the basics of using keyframes, from defining animations to applying them to our elements.

Your Web Designer Toolbox

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

Understanding the Structure of CSS Keyframes

At the core of every CSS animation are keyframes, which define the stages of an animation sequence. Keyframes are declared using the @keyframes rule, followed by an animation name of your choice. The name we use in the example below, changeBackground, is arbitrary – you could name it anything that suits your needs.

Here’s an illustration:

/* Keyframe declaration */
@keyframes changeBackground {
  0%   { background: #ff0000; } /* Red at the start */
  50%  { background: #00ff00; } /* Green in the middle */
  100% { background: #0000ff; } /* Blue at the end */
}

The changeBackground keyframe dictates how the background color of an element will transition during the animation. At the start of the animation (0%), the background is red. At the midway point (50%), the background changes to green. Finally, at the end of the animation (100%), the background transitions to blue.

Applying CSS Keyframes to an Element

Now, let’s apply our keyframes to an HTML element using the animation shorthand property:

/* Applying keyframe to an element */
.myElement {
  animation: changeBackground 2s ease-in-out 1s infinite alternate;
}

In this case, we’ve applied the changeBackground keyframe to an element with the .myElement class. The animation alters the background color of this element over a defined period, according to the stages we set in the keyframe.

Dissecting the Animation Shorthand

The animation shorthand property encapsulates several animation-related properties:

/* The animation shorthand */
animation: changeBackground 2s ease-in-out 1s infinite alternate;
  • changeBackground: The keyframe we defined earlier.
  • 2s: One cycle of the animation will last 2 seconds.
  • ease-in-out: The pace of the animation, starting slow, becoming fast in the middle, and then ending slow.
  • 1s: The animation will start after a delay of 1 second.
  • infinite: The animation will repeat indefinitely.
  • alternate: The animation will alternate directions each cycle.

These are the most commonly used properties but remember that you can also specify animation-fill-mode, animation-play-state, and more. Each property can also be specified separately if you want more control over the animation.

Manipulating Animation Timeline with Percentages and Keywords

Keyframe animations allow changes in style to be dictated using either percentages or the from and to keywords. from represents the start (0%), and to represents the end (100%) of the animation:

/* Keyframe declaration using keywords */
@keyframes fadeInOut {
from { opacity: 0; } /* The element is fully transparent at the start */
to { opacity: 1; } /* The element is fully visible at the end */
}

.myElement {
  animation: fadeInOut 3s ease-in-out 1s infinite alternate;
}

In the fadeInOut keyframe above, we’re changing the element’s opacity. It starts with being fully transparent (opacity: 0) and transitions to being fully visible (opacity: 1). The from and to keywords can be used interchangeably with 0% and 100%, respectively.

So, when this animation is applied to .myElement, the element will gradually fade in over a 3-second duration, from being completely transparent to fully visible. After a 1-second delay, the process will reverse, causing the element to fade out, creating an ongoing cycle of fading in and out due to the infinite and alternate keywords.

Bringing It All Together

Let’s look at a slightly more detailed example:

/* Keyframe declaration */
@keyframes spin {
  0% { transform: rotate(0deg); } /* Element starts at its original position */
  50% { transform: rotate(180deg); } /* Rotates 180 degrees halfway through the animation */
  100% { transform: rotate(360deg); } /* Completes a full rotation at the end */
}

.box {
  width: 100px;
  height: 100px;
  background: #FF4B59; /* Specific shade of red */
  animation: spin 2s linear infinite; /* Applies the spin animation */
}

And here’s our HTML element:

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

In the above example, we define an animation named spin that rotates an element. We apply this animation to a <div> element with the class .box. This <div> is a square with a specific shade of red. It will continue to rotate, creating a loop because of the infinite keyword. The transform property with the rotate() function is used to alter the position of the element, providing the rotation effect. The linear keyword ensures that the rotation speed is consistent throughout the animation.

See the Pen CSS Text Embossing Effect by 1stWebDesigner (@firstwebdesigner) on CodePen.0

Conclusion

CSS keyframes form the foundation of most CSS animations. Naturally, there’s more to learn and experiment with beyond the aspects we covered. For instance, consider exploring the steps() function in CSS animations, which allows you to break your animation into segments, giving you “frame by frame” control.

When it comes to interactive animations, JavaScript can be combined with CSS keyframes to trigger animations based on user actions like clicks or scrolls. Meanwhile, SVG animations offer more complex graphical animations beyond standard HTML elements, allowing you to animate individual parts of an SVG image for intricate visual effects.

As your understanding of CSS keyframes deepens, you’ll be able to leverage them more effectively to improve your designs and their user experience. Consider using animations for user guidance, interaction feedback, or simply to elevate your designs.

However, remember that animations can be resource-intensive. Strive for a balance between the aesthetic appeal of animations and your website’s performance. Techniques such as reducing the number of animated properties or minimizing the number of keyframes can help you achieve this balance.

Disabe Emoji Autoload for Faster WordPress Sites

Website speed is critical to the success of any online venture, which is why we’ll discuss how to disable Emoji Autoload in WordPress in this guide. Not only does site speed have a direct impact on user engagement and conversion rates, but it also influences how search engines rank your site. One often overlooked factor affecting website speed, particularly in WordPress, is the Emoji Autoload feature. Let’s delve into this feature and discuss its implications on site performance.

UNLIMITED DOWNLOADS: Email, admin, landing page & website templates

Starting at only $16.50 per month!

What is Emoji Autoload in WordPress?

Emojis, those fun little icons we often use in our digital conversations, are universally supported on almost all devices and browsers. To ensure emojis display correctly across all platforms, WordPress introduced the Emoji Autoload feature in version 4.2. This feature, which is part of the core WordPress functionalities, automatically loads a JavaScript file (wp-emoji-release.min.js) on every page of your WordPress site, impacting the site’s loading speed.

While this ensures a consistent emoji experience across all devices, it also adds an extra HTTP request to your site on every page load. In the world of web performance, each HTTP request can add to your site’s load time. For websites that do not rely heavily on emojis, this feature can slow down the site unnecessarily.

Why You Should Disable Emoji Autoload

Optimizing your WordPress website for speed involves minimizing unnecessary HTTP requests, including those made by features like Emoji Autoload. By disabling the Emoji Autoload feature in WordPress, you eliminate one such HTTP request from every page load, thereby enhancing your website’s speed. Remember, in the speed race, every millisecond counts. As per the HTTP Archive, among the top contributors to page bloat are HTTP requests.

How to Disable Emoji Autoload

Disabling Emoji Autoload is straightforward and involves adding a short code snippet to your theme’s functions.php file. Remember, before editing any theme files, ensure you have a recent backup of your site and preferably use a child theme to prevent issues when updating your theme.

Here is the code snippet to disable Emoji Autoload:

remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');

This code stops the emoji script from loading on your site, thereby eliminating the associated HTTP request.

The code snippet is made up of two functions:

  • remove_action(‘wp_head’, ‘print_emoji_detection_script’, 7); – This line tells WordPress to stop printing the emoji detection script into the <head> of your website.
  • remove_action(‘wp_print_styles’, ‘print_emoji_styles’); – This line does the same for the emoji styles, preventing them from being printed on your site.

When adding these two lines to your functions.php file and saving your changes, you effectively disable the Emoji Autoload feature.

Wrapping Up

Optimizing your WordPress site for speed involves many tweaks and adjustments, and disabling Emoji Autoload is just one of them. It’s a small change that can contribute to a faster, more efficient website, particularly if emojis are not a critical part of your site’s content. After making these adjustments, it’s crucial to assess the impact on your website’s performance. You might consider using a tool like Lighthouse to monitor your website’s page experience.

Bonus💡: How to Monitor Website Page Experience with Lighthouse

How to Create a CSS Text Embossing Effect

Embossing is a graphical effect used to give the impression that the surface of an image has been raised or pressed in. In web design, an embossed text effect can give your typography a three-dimensional look and feel, often lending an elegant and sophisticated touch to your web pages. With the power of CSS, we can create an embossing text effect without the need for any images or additional software. Let’s explore how to accomplish this.

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

HTML Setup

We start with a basic HTML setup – a <div> element with a class of embossed-text:

<div class="embossed-text">
  Embossed
</div>

Creating the CSS Text Embossing Effect

Next, we turn our attention to the CSS, which gives us the desired embossing effect. We’re using the bold and distinctive Truculenta font:

@import url("https://fonts.googleapis.com/css2?family=Truculenta:wght@900&display=swap");

.embossed-text {
 font-family: "Truculenta", sans-serif; /* Set the font to Truculenta */
 font-size: 4em; /* Increase the text size */
 background: #f8bf32; /* Set the warm, summer-like background color */
 color: #2b1e0d; /* Set a rich dark color for the text */
 text-align: center; /* Center align the text */
 padding: 50px; /* Add padding around the text */
 box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.3); /* Create depth with a box shadow */
 text-shadow: -2px -2px 1px rgba(255, 255, 255, 0.6),
  3px 3px 3px rgba(0, 0, 0, 0.4); /* Create the embossed effect */
}

Let’s break down each CSS property:

  • font-family: 'Truculenta', sans-serif; – This sets our text font to Truculenta, a bold and punchy font that is excellent for effects like this.
  • font-size: 4em; – This sets the size of our text, making it large enough and noticeable. An embossed effect works well with larger font sizes, and 4em is a suitable size for demonstration.
  • background: #F8BF32; and color: #2B1E0D; – These set the background color of our container to a warm summer color, and the text color to a rich dark tone. The contrast between the two colors enhances the embossed effect.
  • text-align: center; and padding: 50px; – These center our text and provide padding around it, ensuring the embossed text is well-positioned and well-spaced.
  • box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.3); – This adds a box shadow around our container, enhancing the depth effect.
  • text-shadow: -2px -2px 1px rgba(255, 255, 255, 0.6), 3px 3px 3px rgba(0, 0, 0, 0.4); – This property is the main focus, creating the embossed effect. The text-shadow property is defined by two shadows here:
    • A light shadow is positioned at the top left (-2px -2px 1px rgba(255, 255, 255, 0.6)). This acts like a light source, contributing to the illusion of depth.
    • A darker shadow is applied at the bottom right (3px 3px 3px rgba(0, 0, 0, 0.4)). This adds to the effect by mimicking a shadow, further enhancing the embossed look.

Through these simple steps, you’ve created an embossed text effect using CSS.

The Result

See the Pen
Spinner Loader with Pure CSS
by 1stWebDesigner (@firstwebdesigner)
on CodePen.0

Final Thoughts

Adding an embossed effect to your text with CSS can introduce a subtle, tactile element to your website. As a designer, it’s one more tool in your toolkit to help differentiate your site. Remember, though, that like all design elements, it should be used thoughtfully and not in excess. It works best when applied to headers or highlighted text, where it can add emphasis without being overbearing.

The beauty of CSS lies in its flexibility and depth. With some experimentation, you can adapt this CSS text embossing effect to suit your design aesthetic. Enjoy exploring the possibilities!

Crafting a Spinning Loader with Pure CSS

Imagine you’re on a website, eagerly waiting for content to load, but all you see is a blank screen. It’s frustrating, isn’t it? The spinning loader, or spinner, is a UI element designed to combat this exact problem. It informs users that the system hasn’t stalled — it’s just busy fetching data. Today, we’ll be crafting a loader with pure CSS that effectively communicates this busy state.

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


Crafting a Loader with Pure CSS

We’ll first structure our spinner using HTML, then we’ll style and animate it using CSS.

HTML Structure for the CSS Loader

<div class="spinner"></div>

Our structure is lightweight, comprising a single div element with a class of “spinner”. This div will serve as the container for our loader.

Now that we’ve set the HTML structure, let’s proceed to craft the spinner using pure CSS.

CSS Styling and Animation for the Loader

/* Defining the Spinner */
.spinner {
  border: 14px solid #e8e8e8; /* Light grey */
  border-top: 14px solid #f65b5f; /* Our color */
  border-radius: 50%; /* Circle */
  width: 80px; 
  height: 80px; 
  animation: spin 1s ease infinite; /* Animation */
}

/* Animation for Spinning Effect */
@keyframes spin {
    to {
        transform: rotate(1turn); /* Full rotation */
    }
}

In the CSS, we define the .spinner class where we design the visual aspects and motion of our loader:

  • The border is set to be 14px wide with a light grey color (#e8e8e8). This creates a circle, which becomes our loader’s base.
  • The border-top is given a solid, visually appealing color (#f65b5f) to make it stand out against the lighter circle.
  • We then make the border circular by setting the border-radius property to 50%.
  • The dimensions of the spinner are set with the width and height properties, each set to 80px, giving our spinner a balanced size.
  • The animation property defines our animation:
    • The animation’s name is “spin”, which we have defined in the @keyframes rule.
    • The duration is set to 1s, striking a balance between a fast and slow spin.
    • The animation-timing-function is set to ease, giving the animation a more natural feel.
    • The animation-iteration-count is set to infinite, meaning the animation will run indefinitely — perfect for a loader.

Finally, the @keyframes rule spin defines what the animation does — it rotates the spinner one full turn (1turn).

The Result

See the Pen
Spinner Loader with Pure CSS
by 1stWebDesigner (@firstwebdesigner)
on CodePen.0

Wrapping Up

Crafting a neat loader isn’t just about aesthetics; it’s a crucial tool that communicates system activity to users. When paired with effective UX writing and controlled with JavaScript, loaders can do more than indicate data-fetching; they can convey various states of processes in complex applications. Accompanying messages can offer insights like the operation type or completion time estimate.

Consider an e-commerce site using a small spinner on a “Buy Now” button to show a transaction is underway, with a note saying “Processing your purchase…”. For tasks with longer wait times, like report generation, a fullscreen loader might be suitable, potentially with a progress bar or comforting message such as “Compiling your custom report…”.

But it’s vital that the loader and its messages fit your design language and meet user expectations. The goal is to reduce wait-time friction and create a smooth, intuitive user experience.

Creating Ghost Buttons with CSS

In recent years, ghost buttons have solidified their position as a trendy and elegant element. Characterized by their transparent nature and minimalist outline, ghost buttons, also known as “empty” or “naked” buttons, offers a sleek, clean aesthetic that can improve user experience. Below, we’ll explore how to create such a ghost button using CSS.

Kinsta

UX Consideration for Ghost Buttons

Ghost buttons are typically bordered by a fine line and contain plain text within. Often used as CTAs, they provide a neat appearance, grabbing attention with high contrast while offering a fresh take on the “flat” look.

Furthermore, they’ve become popular because they’re simple to design, help create focal points without overwhelming the user, and improve aesthetics by maintaining a clean UI. Plus, they easily integrate into any design due to their ability to blend with the environment.

Despite their benefits, ghost buttons must be used wisely. Inappropriate placement can cause them to blend too much with the overall layout, and in worst-case scenarios, they can be mistaken for input fields. It would be best if you were cautious when using them, especially on a background image, as they can fall too far into the background and lead to text legibility issues.

Now that we understand certain UX implications, let’s create one using HTML and CSS.

Setting Up the Structure for Our Ghost Button

The first step to creating a Ghost Button with CSS involves setting up the HTML structure. In this setup, we’re using the <a> element to serve as the base for our Ghost Button. Here’s how it looks:

<a href="https://1stwebdesigner.com/designing-engaging-3d-buttons-css/" class="elegant-ghost-button" target="_blank">Featured</a> 

Styling the Ghost Button with CSS

The next step is to define the appearance of our ghost button. Here’s a look at the CSS code we’ll be using:

body {
  background: #1b1f25;
}

/* Styling our Ghost Button */
.elegant-ghost-button {
    text-align: center;  /* Centers the button text */
    color: #ffffff;  /* Sets text color */
    background: #1b1f25;  /* Matches button background with body background for the 'ghost' effect */
    border: 1px solid #ffffff;  /* Sets a thin white border around the button */
    font-size: 18px;
    padding: 12px 12px;
    display: inline-block;  /* Enables the button to align better with other elements */
    text-decoration: none;  /* Removes the default underline of the anchor text */
    font-family: "Maven Pro", sans-serif;
    min-width: 120px;  /* Ensures a sufficient clickable area */
    transition: background 0.3s ease-in-out, color 0.3s ease-in-out;  /* Adds a smooth color transition on hover */
}

/* Changes color and background on hover to provide dynamic feedback */
.elegant-ghost-button:hover, .elegant-ghost-button:active {
  color: #1b1f25;
  background: #ffffff;
}

Initially, the body background color is set to #1b1f25, a dark hue that will contrast effectively with our ghost button.

Then we move to the .elegant-ghost-button class to define our button’s look and behavior:

  • text-align: center – This property is used to horizontally align the text within the button, aiding in visual balance.
  • color and background – The color property is set to #ffffff, which results in white text. The background is the same color as the body’s background. This helps create the ‘ghost’ effect, where the button appears to blend with the background.
  • border: 1px solid #ffffff – This property outlines the button with a thin white border, further defining the ghost button effect.
  • font-size and font-family – These properties specify the text’s size (18px) and font (“Maven Pro”, sans-serif) for an easy-to-read and attractive button label.
  • padding: 12px 24px – The padding property provides space around the text and also defines the button’s dimensions.
  • display: inline-block – This property ensures the button aligns properly with other inline elements.
  • text-decoration: none – This property is used to remove the default underline that usually accompanies anchor text.
  • transition – This property smoothens the color change over a 0.3 seconds duration when the button is hovered over or clicked. The effect is engaging, as the background color turns white and the text color darkens to #1b1f1f.

In addition to the static properties of the button, the hover effect is crucial to its interactivity. The .elegant-ghost-button:hover, .elegant-ghost-button:active selectors are used to switch the background and text color when the user interacts with the button, providing clear feedback that the button is clickable.

In a more practical scenario, these properties and their values might require adjustments to resonate with your website’s design theme and functional requirements. For instance, you may need to modify the button’s dimensions, colors, font properties, and transition duration to align with your site’s aesthetic. To improve the responsiveness across different devices, you might need to employ media queries to adjust padding and font size according to the viewport size. Lastly, for layouts using flexbox or grid, the management of the button’s size and positioning would need to be considered.

The Result

See the Pen
Ghost Button CSS #1
by 1stWebDesigner (@firstwebdesigner)
on CodePen.0

Final Thoughts

Ghost buttons introduce a minimalist and clean design to web pages, making them particularly useful in contexts where a simplistic, understated aesthetic is desired. However, due to their subtle nature, they may not stand out as prominently as other design elements. As such, using them as the primary CTA on your webpage might not be the most effective strategy.

They often shine when used for secondary or tertiary actions, where their understated elegance can enhance the overall design without drawing unnecessary attention. For instance, they can be used as navigational buttons, form submission buttons, or secondary action prompts that complement a primary, more conspicuous CTA.

Remember, successful design hinges on understanding and applying elements in their effective contexts. Ghost buttons, when used judiciously, can contribute to a visually pleasing and user-friendly interface.

How to Create a CSS-Only Toggle Button

With the growing eco-system of CSS, designers, and developers are continually seeking ways to leverage its power for interactive UI elements. One such element is the toggle button, an essential interactive component. While more complex features might require JavaScript or additional libraries, this guide focuses on how to create a CSS-only toggle button, providing you with the fundamental understanding that serves as the stepping stone to more advanced concepts.

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

Setting the HTML Structure for Our Toggle Button

The first step towards creating a CSS-only toggle button is setting up a suitable HTML structure. We’ll use the following code:

<label class="toggle-switch">
  <input type="checkbox">
  <span class="switch"></span>
</label>

Our structure begins with a <label> element, containing an <input> of type checkbox and a <span>. The checkbox input is what we’ll be toggling. The <span> element, meanwhile, will be visually representing our switch. When the checkbox is clicked, we’ll use CSS to visually “move” the switch within the label.

Styling the Toggle Button with CSS

With our HTML structure established, we turn to CSS to bring our toggle button to life. Here’s the CSS code with comments explaining each section:

/* Defines the switch's outer container */
.toggle-switch {
  display: inline-block;  
  position: relative;     
  width: 60px;            
  height: 34px;           
}

/* Hides the actual checkbox input */
.toggle-switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

/* Styles the switch's slider */
.switch {
  position: absolute;    
  cursor: pointer;       
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;        
  border-radius: 34px;    
}

/* Styles the switch's circle that moves back and forth */
.switch::before {
  position: absolute;
  content: "";            
  height: 26px;           
  width: 26px;
  left: 4px;              
  bottom: 4px;
  background-color: white;
  transition: .4s;        
  border-radius: 50%;    
}

/* Changes the background color and circle position when checked */
input:checked + .switch {
  background-color: #4caf50; 
}

input:checked + .switch::before {
  transform: translateX(26px);
}

In our CSS code, we initially set up a container for our switch using the .toggle-switch rule. This rule sets the dimensions and positioning of the switch.

Next, the .toggle-switch input rule hides the actual checkbox input. While it’s hidden from the visual UI, the input remains functional and can be interacted with programmatically.

The .switch rule then provides styling for the switch’s slider, setting the color, shape, and transition effect.

The .switch::before rule styles the circle within the switch, which moves left and right when the switch is toggled.

Lastly, the input:checked + .switch and input:checked + .switch::before rules control the appearance of the switch when it’s checked, changing the background color of the slider and the position of the circle, respectively.

See the Pen
Button Toggle with CSS only
by 1stWebDesigner (@firstwebdesigner)
on CodePen.0

Going Beyond the Basics

The CSS-only toggle button in this tutorial is a simplified model. When complexity escalates with various user interactions and state management, JavaScript may become necessary. If your design demands more detail—icons, labels, or complex transitions—you’ll need a more advanced mix of HTML, CSS, or even SVG and JavaScript. These variations present their own trade-offs in simplicity, flexibility, and browser compatibility, which are critical considerations when designing UI elements.

Venturing beyond this demonstration, the principles we’ve touched upon here will act as your compass. Remember, effective design doesn’t solely hinge on mastering individual technologies, but on understanding how they synergize.

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!

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.