Javascript Articles

Found 5,339 articles

How to Add CSS Rules to a Stylesheet with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 488 Views

The insertRule() method helps us add CSS rules to a stylesheet dynamically using JavaScript, while deleteRule() removes existing rules. These methods allow you to modify styles programmatically without editing the original CSS code. Syntax // Insert a rule stylesheet.insertRule(rule, index); // Delete a rule stylesheet.deleteRule(index); Method 1: Insert a CSS Rule To insert a rule at a defined position, use the insertRule() method. First, get the stylesheet using getElementById() and access its sheet property − body { ...

Read More

Auto Grow a Textarea with JavaScript in CSS

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 493 Views

Auto-growing textareas improve user experience by dynamically adjusting their height based on content length. This eliminates the need for scrollbars and provides a seamless typing experience. We can achieve this functionality using JavaScript to monitor content changes and CSS to control the visual appearance. Syntax textarea { resize: none; overflow: hidden; min-height: initial-height; } Method 1: Basic Auto-Growing Textarea This example demonstrates a simple auto-growing textarea that expands vertically as content is added − ...

Read More

Typing and Deleting Effect with JavaScript and CSS

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

With the help of CSS animations, we can create a typewriter typing and deleting effect using JavaScript. The infinite effect continuously cycles through words, typing them character by character and then deleting them to create an engaging visual animation. Syntax @keyframes animationName { to { opacity: value; } } selector { animation: name duration iteration-count; } HTML Structure First, create a container with two paragraph elements − one for the text and another for the cursor: ...

Read More

Get and Set CSS Variables with JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 14K+ Views

To get and set CSS variables with JavaScript, we can use various methods. The getComputedStyle() method gives an object which includes all the styles applied to the target element. The getPropertyValue() method is used to obtain the desired property from the computed styles. The setProperty() method is used to change the value of CSS variable. Syntax /* Getting CSS Variable */ getComputedStyle(element).getPropertyValue('--variable-name'); /* Setting CSS Variable */ element.style.setProperty('--variable-name', 'value'); Methods Used MethodPurpose getComputedStyle()Returns computed styles of an element getPropertyValue()Gets the value of a specific CSS property setProperty()Sets the value of a CSS ...

Read More

How to create a quotes slideshow with CSS and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

A quotes slideshow is an interactive component that displays inspirational quotes with smooth navigation controls. It combines HTML structure, CSS styling, and JavaScript functionality to create an engaging user experience with previous/next buttons and clickable dot indicators. Syntax .slideContainer { position: relative; max-width: value; } .Slide { display: none; /* Hide all slides by default */ } .prevBtn, .nextBtn { position: absolute; top: 50%; } HTML Structure First, create the HTML structure ...

Read More

How to create a popup chat window with CSS and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 4K+ Views

On a website, in the bottom-right, you must have seen a popup chat windows. Can be mostly seen on website hosting websites. This allows a user to directly ask sales questions before buying the product. Such popup chat window can be easily created on a web page with CSS and JavaScript. Let us see how. Syntax .chat-button { position: fixed; bottom: value; right: value; display: block; } .chat-window { position: fixed; display: ...

Read More

How to create a \"coming soon page\" with CSS and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 342 Views

A "coming soon" page is a temporary webpage displayed to visitors before a website launches. This page typically includes an attractive design, launch information, and a countdown timer to create anticipation. We'll create one using CSS for styling and JavaScript for the countdown functionality. HTML Structure First, let's set up the basic HTML structure with a background container and centered content − COMING SOON ...

Read More

How to create a fixed/sticky header on scroll with CSS and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

A fixed/sticky header remains at the top of the page when users scroll down, providing constant navigation access. This can be achieved using CSS positioning and JavaScript to detect scroll events. CSS Approach The simplest method uses the CSS position: sticky property − .header { position: sticky; top: 0; z-index: 1000; } Example 1: Pure CSS Sticky Header Here's a basic sticky header using only CSS − body { ...

Read More

How to create a snackbar / toast with CSS and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 758 Views

If you want to show notifications to the user about any information, such as a coupon for buying the product, you can create a snackbar. Use them as popups to display a message at the bottom of the screen. Generally, the snackbar vanishes after some time with fade-in and fade-out animations. Let us see how to create a snackbar on the click of a button with CSS and JavaScript. Syntax .snackbar { visibility: hidden; position: fixed; bottom: 30px; left: 50%; ...

Read More

How to create a \"to-do list\" with CSS and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 477 Views

A to-do list allows you to manage your tasks effectively. When you type what needs to be done and press Enter, the task gets added to the list, and you can continue adding more tasks or click on existing ones to remove them. Syntax /* Input styling */ .todoInput { padding: value; width: value; font-size: value; border: value; } /* List item styling */ li { list-style: none; padding: value; ...

Read More
Showing 1–10 of 5,339 articles
« Prev 1 2 3 4 5 534 Next »
Advertisements