A beautiful, modern calculator with dark/light theme support, smooth animations, and responsive design inspired by iOS/Android calculators.
- Clean, minimalist interface with flat design principles
- Light blue gradient background for a soothing visual experience
- Soft shadows and subtle borders instead of harsh 3D effects
- Material Design inspired color scheme
- Dark/Light mode toggle with smooth transitions
- Persistent theme preference saved in localStorage
- Animated theme switching with rotation effect
- Basic arithmetic operations: Addition (+), Subtraction (−), Multiplication (×), Division (÷)
- Decimal number support with proper validation
- Clear all (AC) and delete last digit (⌫) functions
- Error handling for division by zero and invalid operations
- Floating point precision handling to avoid calculation errors
- Operation display showing current calculation (e.g., "25 +")
- Complete calculation history shown after pressing equals (e.g., "25 + 15 =")
- Active operator highlighting with visual feedback
- Haptic feedback on mobile devices
- Smooth animations for all interactions
- Button press feedback with scale and opacity effects
- Full keyboard support for all operations
- Touch-friendly interface for mobile devices
- Responsive design that works on all screen sizes
- Prevent zoom on double-tap for better mobile experience
- A modern web browser (Chrome, Firefox, Safari, Edge)
- Python 3.x (for local development server)
- Clone or download the project files
- Navigate to the project directory
- Start a local server:
python -m http.server 8000
- Open your browser and go to
http://localhost:8000
You can also open index.html directly in your browser, but using a local server is recommended for the best experience.
Calculator/
├── index.html # Main HTML structure
├── style.css # Styling and animations
├── script.js # Calculator logic and interactions
└── README.md # Project documentation
- Semantic HTML5 with proper accessibility attributes
- Grid layout for button arrangement
- Data attributes for clean JavaScript interaction
- CSS Grid for responsive button layout
- CSS Custom Properties for consistent theming
- Flexbox for display alignment
- CSS Animations and transitions for smooth UX
- Media queries for responsive design
- Backdrop-filter for glassmorphism effect
- ES6 Class-based structure for clean code organization
- Event delegation for efficient event handling
- State management for calculator operations
- Error handling with user-friendly feedback
- Local storage for theme persistence
class Calculator {
constructor() // Initialize calculator
inputNumber() // Handle number input
inputOperator() // Handle operator selection
calculate() // Perform calculations
updateDisplay() // Update main display
updateOperationDisplay() // Update operation history
toggleTheme() // Switch between themes
}- Background: Light blue gradient (
#e3f2fdto#bbdefb) - Numbers: White buttons with subtle shadows
- Operators: Blue (
#2196f3) - Equals: Green (
#4caf50) - Clear: Orange (
#ff9800)
- Background: Dark gradient (
#1a1a2eto#16213e) - Numbers: Dark gray buttons
- Operators: Blue (consistent with light mode)
- Enhanced contrast for accessibility
- Desktop: Full-featured layout with hover effects
- Tablet: Optimized button sizes and spacing
- Mobile: Touch-friendly interface with haptic feedback
- Small screens: Compact layout with adjusted font sizes
- New operations: Add to
performCalculation()method - UI elements: Update HTML structure and CSS styling
- Themes: Modify CSS custom properties
- Colors can be easily changed in the CSS file
- Animation durations and effects are configurable
- Button layouts can be modified through CSS Grid properties
- Large numbers: Display truncates very large numbers
- Scientific notation: Limited support for exponential notation
- Memory functions: M+, M-, MR not implemented
- Advanced operations: No support for square root, percentage, etc.
- Scientific calculator mode with advanced functions
- Calculation history with persistent storage
- Memory functions (M+, M-, MR, MC)
- Keyboard shortcuts display
- Sound effects for button presses
- Multiple themes beyond dark/light
- Export calculations to clipboard
Feel free to fork this project and submit pull requests for any improvements!
This project is open source and available under the MIT License.
- Inspired by iOS and Android calculator designs
- Material Design principles for color and interaction patterns
- Modern web development best practices
Enjoy calculating! 🧮✨