![]() |
VOOZH | about |
Bootstrap 5 Accordion SASS can be used to change the default values provided for the accordion by customizing scss file of bootstrap5.
Step 1: Install bootstrap using following command:
npm i bootstrapStep 2: Create your custom scss file and write the variable you want to override. Include the bootstrap scss file using import.
$class_to_override: values;
@import "node_modules/bootstrap/scss/bootstrap"
Step 3: Convert the file to CSS using live server extension.
Step 4: Include the converted scss file to your HTML file.
The custom scss file name is “custom.scss” and "custom.css" is the converted file
$accordion-padding-y:value
@import "./node_modules/bootstrap/scss/bootstrap"
Example 1: In this example, we make use of the $accordion-color, $accordion-padding-y, $accordion-padding-x, $accordion-border-color, $accordion-border-width, $accordion-button-color, $accordion-button-bg, $accordion-button-active-bg, $accordion-button-active-color variables.
In the scss file, the accordion color is changed to green color, the top and bottom padding of accordion is changed to 1.3rem, the left and right padding is changed to 2.5rem, the border color is changed to black, the border width is changed to 3.5px, the border radius is changed to 3rem, the text color of the accordion button is changed to white, the background color of the accordion button is changed to green color, the background color of the active accordion button is changed to white, the text color of the active accordion button is changed to green.
custom.scss
CSS file created after conversion
custom.css
index.html
Output:
Example 2: In this example, making use of the $accordion-color, $accordion-bg, $accordion-body-padding-y, $accordion-body-padding-x, $accordion-button-padding-y, $accordion-button-padding-x, $accordion-icon-width, $accordion-icon-color, $accordion-icon-active-color, $accordion-icon-transition, $accordion-icon-transform variables.
In the scss file, the accordion color is changed to white, the background color of the accordion is changed to green, the top and bottom padding of the accordion body is changed to 4.5rem, the left and right padding of the accordion body is changed to 3.5rem, the top and bottom padding of the accordion button is changed to 2rem, the left and right padding of the accordion button is changed to 7rem, the width of the accordion icon is changed to 2rem, the color of the accordion icon is changed to white, the color of the active accordion icon is changed to black, the transition duration of the accordion icon is changed to 2 seconds with 'ease-in-out', the transformation of the accordion icon is changed to rotate in 180 degrees.
custom.scss
CSS file created after conversion
custom1.css
index.html: The above CSS file "custom1.css" is included in this code.
Output:
Reference: https://getbootstrap.com/docs/5.0/components/accordion/#sass