Tips for customizing your MUI slider design

import * as React from "react";
import Box from "@mui/material/Box";
import Slider from "@mui/material/Slider";

function valuetext(value) {
  return `${value}°C`;
}

export default function RangeSlider() {
  const [value, setValue] = React.useState([20, 37]);

  const handleChange = (event, newValue) => {
    setValue(newValue);
  };

  return (
    <Box sx={{ width: 300 }}>
      <Slider
        getAriaLabel={() => "Temperature range"}
        value={value}
        onChange={handleChange}
        valueLabelDisplay="auto"
        getAriaValueText={valuetext}
      />
    </Box>
  );
}

Is it possible to style the range within the thumb green and the range outside of both thumbs a lighter green as shown in the image below?

Answer №1

You have the ability to personalize your slider using the styled utility:

const green500 = "#228b22";
const green900 = "#7FFF00";

const CustomSlider = styled(Slider)(({ theme }) => ({
  color: green500, //set the color of the slider between thumbs
  "& .MuiSlider-thumb": {
    backgroundColor: green500 //customize the color of the thumbs
  },
  "& .MuiSlider-rail": {
    color: green900 //adjust the color of the slider outside the area between thumbs
  }
}));

See Demo

Answer №2

Make sure to add the following classes to your CSS stylesheet. The "Track" class represents the area between the slider thumbs, while the "Rail" class refers to the space outside both thumbs.

.CustomSlider-thumb{
  color: blue;
}
.CustomSlider-rail{
  color: cyan;
}
.CustomSlider-track{
  color: navy;
}

Answer №3

To achieve this in a different way, you can create your own custom styles.

const CustomizedSliderStyles = {
    '& .CustomThumb': {
        color: "#8f4c59"
    },
    '& .CustomTrack': {
        color: "#8f4c59"
    },
    '& .CustomRail': {
        color: "#dbe39f"
    },
    '& .CustomActive': {
        color: "#72b7be"
    }
};

Then simply apply them like so:

<Slider customStyles={CustomizedSliderStyles} />

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Uploading photos to Postgres through express/multer

Currently, I am using Postman to send images to a POST route through the Express library. However, when I retrieve the buffer of binary data, I am unable to process it accordingly. Will using body-parser resolve this issue? This is how I am uploading the ...

Receiving an error stating that .startsWith() is not a function in react native

I'm having trouble searching for items using a search bar. The original items are in 'prod', but I keep encountering errors such as 'startsWith() is not a function' and sometimes '.toLowerCase() is not a function'. const ...

The issue of the "port" attribute not working for remotePatterns in the Image component has been identified in Next.js 13's next.config.js

I've encountered an issue with the code snippet below. I'm attempting to utilize remotePatterns in my next.config.js file to enable external images. Strangely, when I set the port to an empty string "", it functions correctly. However, specifying ...

I need help with properly placing the DataGrid component within Material UI

https://i.stack.imgur.com/Cn4fg.png No matter how many different solutions I try, I just can't seem to get this grid to fit perfectly within this space. I'm struggling to understand the sizing in Material UI and why the column titles are missing ...

Image not showing up when using drawImage() from canvas rendering context 2D

Need help with drawImage() method in JavaScript <head> </head> <body> <script type = "text/javascript"> var body, canvas, img, cxt; body = document.getElementsByTagName("body" ...

How can you make the contents of a <DIV> expand?

Picture a scenario where I have a navigation bar in the header of my web page, consisting of several links. What I want is for these links to expand horizontally to fill the parent container without me having to hard-code based on the number of links. In o ...

Sending a JavaScript string to a PHP script from a Chrome extension content script

I am currently developing a chrome extension that is designed to extract text data from specific websites when I visit them, and then store this data in a SQL database. The JavaScript code for data extraction is functioning correctly and is able to capture ...

The AJAX response is not functioning as expected

I've encountered an issue with my AJAX code for an online food store. Every time I run it, a pop-up message saying something went wrong appears instead of the expected output. I suspect there might be an error in either the connection handlers or the ...

Attaching a CSS file to a personalized WordPress widget

After much searching and struggling due to language barriers or lack of PHP knowledge, I couldn't figure out how to achieve this: public function widget( $args, $instance ) { ?> <div style="padding: 0 0 14% 0"> <div class="m ...

I'm having trouble getting the npm install for classnames to work within my li tag

I need some help with React JS. I'm attempting to merge my classes using the npm package called classnames. https://www.npmjs.com/package/classnames However, I'm encountering an issue: classnames doesn't seem to be working as expecte ...

Exploring the intricacies of setting colspan in a Material-UI React table

I've utilized a Material React table by inserting the code <MaterialReactTable columns={columns} data={data} />. I'm interested in having a colspan that spans across two to three columns, like in the example below. Can this be achieved wit ...

Implementing pagination for images offers a user-friendly browsing experience

My friend and I are in the process of creating a website that displays images from two directories in chronological order. The image name serves as a timestamp, and we generate a JSON object using PHP with the code below: <?php $files = array(); $dir ...

Ways to properly align a navigation bar at the center of the webpage while maintaining the

Whenever I zoom in or out on my page, the homepage button loses its color and fails to expand to the right side. So, I have two main goals: 1) To center the selected area (highlighted by a red border in the image). 2) To extend the green color of the hom ...

Using modules in Next.js to expand functionality

I am currently working on a project that I need to integrate into Next JS as a module. Utilizing npm link, I have successfully added the module to my Next JS repository as a component. However, the integration is breaking due to webpack loaders. Do I need ...

Material Style Minimal - There is a slight space between the text field and the colored line at the bottom

Having a problem with Material Design Lite text field where there is a small gap between the bottom colored line and the gray starting line. Every MDL text field example I try on my page shows the same issue. What could be causing this locally? My frontend ...

"Troubleshooting issue in Django 1.6.2 where CSS styles are not being applied to

I am encountering an issue with this code and would greatly appreciate some assistance. The base.html file contains a {% block content %}{% endblock %}. I have created a Signup.html file structured like this: {%extends 'base.html'%} {% block co ...

What could be causing the 401 Unauthorized error to occur when attempting to request API data from React?

In my current project, I am in the process of developing a server-rendered application using Express and React. I have encountered an issue while trying to query data from the back-end on the client side. The workflow is as follows: Users navigate to a s ...

The sum of total values in Material UI range sliders is capped at 100

Is it possible to ensure that the total of three Material UI sliders, each denoting percentage values, always remains at 100? I want the sliders' values to automatically adjust in order to maintain this total. How can this functionality be achieved? ...

Issue in MUI V5: MakeStyles styles being overridden

After recently updating to version 5.0.0-alpha.25 (moving from 5.0.0-alpha.10), I've encountered an issue with makeStyles not working properly. Despite checking for any breaking changes, I couldn't find anything related to this specific problem, ...

Error: Surprising token found in ReactJS application on CodeSandbox

Encountering an unexpected token on line 5 error in my ReactJS project when testing it on CodeSandbox. Interestingly, the app runs smoothly without errors on my local machine. import React, { Component } from 'react'; import Header from ' ...