This is a solution to the Pricing component with toggle challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
- View the optimal layout for the component depending on their device's screen size.
- Toggle between monthly and annual pricing using both mouse and keyboard.
- Bonus: Complete the challenge using semantic HTML, CSS, LESS, and vanilla JavaScript.
Desktop Design
Mobile Design
- Semantic HTML5 markup
- Bootstrap 5 for layout and styling
- LESS preprocessor for modular and dynamic styling
- Vanilla JavaScript for interactivity
- Mobile-first workflow
This project reinforced my knowledge of:
- LESS Preprocessor: Using variables, mixins, and nesting to write modular, maintainable, and dynamic CSS.
- JavaScript for Accessibility:
- Implementing keyboard-accessible features by toggling
aria-checkedfor the toggle switch. - Writing dynamic scripts to change pricing values.
- Implementing keyboard-accessible features by toggling
- Bootstrap Customization: Integrating Bootstrap with custom styles and overrides.
- Responsive Design:
- Designing for mobile-first.
- Adjusting layouts using media queries.
Example of the LESS code for the toggle switch:
.toggle {
background: linear-gradient(to bottom, @linear-gradient-1, @linear-gradient-2);
&:hover {
background: linear-gradient(to bottom, lighten(@linear-gradient-1, 10%), lighten(@linear-gradient-2, 10%));
}
&.active {
&:before {
transform: translateX(-40px);
}
}
}In future projects, I aim to focus on:
- Improving the accessibility of dynamic components (like this toggle).
- Deepening my understanding of advanced LESS features, such as conditionals and loops.
- Experimenting with utility-first CSS frameworks like Tailwind CSS alongside preprocessors.
- LESS Documentation - The official LESS documentation was invaluable for setting up and understanding advanced features.
- Bootstrap 5 Documentation - For layout and component customizations.
- MDN Web Docs - For JavaScript functionality, especially ARIA attributes.
LESS is a CSS preprocessor that extends CSS with dynamic behavior such as variables, nesting, mixins, and more. To use LESS in your project:
- Ensure you have Node.js and npm installed. If not, download and install them from Node.js.
- Install LESS globally by running:
npm install -g less
To compile the style.less file into CSS:
- Run the following command:
lessc style.less style.css
- Include the compiled
style.cssfile in your HTML, as shown in the code.
You can also use a LESS watcher tool like less-watch-compiler for live compilation during development:
npm install -g less-watch-compiler
less-watch-compiler ./ ./ style.less- LinkedIn - Yashi Singh
- Frontend Mentor - @Yashi-Singh-9
Big thanks to Frontend Mentor for creating such realistic challenges. This project was a fantastic way to refine my skills in LESS and JavaScript.

