Skip to content

BMI CALCULATOR #426

@acharyahealer-ux

Description

@acharyahealer-ux
<title>HealthMate BMI Calculator | Calculate Your Body Mass Index</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
    body {
        background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
        color: #333;
        line-height: 1.6;
        min-height: 100vh;
        padding: 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .container {
        max-width: 1200px;
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 300px;
        gap: 20px;
        margin-top: 20px;
    }
    
    @media (max-width: 900px) {
        .container {
            grid-template-columns: 1fr;
        }
    }
    
    header {
        text-align: center;
        margin-bottom: 30px;
        width: 100%;
        color: white;
    }
    
    h1 {
        font-size: 2.8rem;
        margin-bottom: 10px;
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    }
    
    .tagline {
        font-size: 1.2rem;
        opacity: 0.9;
    }
    
    .calculator-card {
        background: white;
        border-radius: 15px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
        padding: 30px;
        margin-bottom: 20px;
    }
    
    .form-group {
        margin-bottom: 20px;
    }
    
    label {
        display: block;
        margin-bottom: 8px;
        font-weight: 600;
        color: #444;
    }
    
    input, select {
        width: 100%;
        padding: 14px;
        border: 2px solid #ddd;
        border-radius: 8px;
        font-size: 16px;
        transition: border-color 0.3s;
    }
    
    input:focus, select:focus {
        border-color: #2575fc;
        outline: none;
    }
    
    .gender-selection {
        display: flex;
        gap: 15px;
        margin-bottom: 20px;
    }
    
    .gender-option {
        flex: 1;
        text-align: center;
        padding: 15px;
        border: 2px solid #ddd;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.3s;
    }
    
    .gender-option.selected {
        border-color: #2575fc;
        background-color: #f0f7ff;
    }
    
    .gender-option i {
        font-size: 24px;
        margin-bottom: 8px;
        display: block;
    }
    
    .unit-toggle {
        display: flex;
        align-items: center;
        margin-bottom: 15px;
        gap: 10px;
    }
    
    .toggle-switch {
        position: relative;
        display: inline-block;
        width: 60px;
        height: 30px;
    }
    
    .toggle-switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }
    
    .slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: #ccc;
        transition: .4s;
        border-radius: 34px;
    }
    
    .slider:before {
        position: absolute;
        content: "";
        height: 22px;
        width: 22px;
        left: 4px;
        bottom: 4px;
        background-color: white;
        transition: .4s;
        border-radius: 50%;
    }
    
    input:checked + .slider {
        background-color: #2575fc;
    }
    
    input:checked + .slider:before {
        transform: translateX(30px);
    }
    
    .unit-label {
        font-weight: 600;
        color: #444;
    }
    
    .height-input {
        display: none;
    }
    
    .height-input.active {
        display: block;
    }
    
    button {
        width: 100%;
        padding: 16px;
        background: linear-gradient(to right, #2575fc, #6a11cb);
        color: white;
        border: none;
        border-radius: 8px;
        font-size: 18px;
        font-weight: 600;
        cursor: pointer;
        transition: transform 0.2s, box-shadow 0.2s;
        margin-top: 10px;
    }
    
    button:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    }
    
    .result-container {
        text-align: center;
        padding: 20px;
        margin-top: 30px;
        border-radius: 10px;
        background: #f8f9fa;
        display: none;
    }
    
    .bmi-value {
        font-size: 3rem;
        font-weight: 700;
        margin: 15px 0;
    }
    
    .bmi-category {
        font-size: 1.5rem;
        font-weight: 600;
        margin-bottom: 15px;
        padding: 8px 15px;
        border-radius: 30px;
        display: inline-block;
    }
    
    .underweight { background: #ffc107; color: #333; }
    .normal { background: #28a745; color: white; }
    .overweight { background: #fd7e14; color: white; }
    .obese { background: #dc3545; color: white; }
    
    .recommendations {
        margin-top: 20px;
        text-align: left;
        padding: 15px;
        background: white;
        border-radius: 8px;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
    }
    
    .ads-container {
        background: white;
        border-radius: 15px;
        padding: 20px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
        height: fit-content;
    }
    
    .ad-placeholder {
        background: #f8f9fa;
        border: 2px dashed #ddd;
        border-radius: 8px;
        padding: 30px;
        text-align: center;
        margin-bottom: 20px;
        color: #777;
    }
    
    .ad-title {
        font-size: 1.2rem;
        margin-bottom: 15px;
        color: #444;
        font-weight: 600;
    }
    
    footer {
        margin-top: 40px;
        text-align: center;
        color: white;
        opacity: 0.8;
        font-size: 0.9rem;
        width: 100%;
        padding: 20px;
    }
    
    .disclaimer {
        max-width: 800px;
        margin: 20px auto;
        background: rgba(255, 255, 255, 0.1);
        padding: 15px;
        border-radius: 8px;
        font-size: 0.9rem;
    }
</style>

HealthMate BMI Calculator

Calculate your Body Mass Index based on age and gender

<div class="container">
    <div class="main-content">
        <div class="calculator-card">
            <div class="form-group">
                <label for="age">Age (1-100 years)</label>
                <input type="number" id="age" min="1" max="100" value="25" required>
            </div>
            
            <label>Gender</label>
            <div class="gender-selection">
                <div class="gender-option selected" id="male">
                    <i class="fas fa-mars"></i>
                    <span>Male</span>
                </div>
                <div class="gender-option" id="female">
                    <i class="fas fa-venus"></i>
                    <span>Female</span>
                </div>
            </div>
            
            <div class="form-group">
                <label>Height Unit</label>
                <div class="unit-toggle">
                    <span class="unit-label">cm</span>
                    <label class="toggle-switch">
                        <input type="checkbox" id="heightUnitToggle">
                        <span class="slider"></span>
                    </label>
                    <span class="unit-label">in</span>
                </div>
                
                <div class="height-input active" id="heightCm">
                    <label for="heightCmInput">Height (cm)</label>
                    <input type="number" id="heightCmInput" placeholder="Enter height in centimeters" required>
                </div>
                
                <div class="height-input" id="heightIn">
                    <label for="heightInInput">Height (inches)</label>
                    <input type="number" id="heightInInput" placeholder="Enter height in inches" required>
                </div>
            </div>
            
            <div class="form-group">
                <label for="weight">Weight (kg)</label>
                <input type="number" id="weight" placeholder="Enter weight in kg" required>
            </div>
            
            <button id="calculate-btn">Calculate BMI</button>
            
            <div class="result-container" id="result">
                <h2>Your BMI Result</h2>
                <div class="bmi-value" id="bmi-value">23.4</div>
                <div class="bmi-category normal" id="bmi-category">Normal Weight</div>
                
                <div class="recommendations">
                    <h3>Health Recommendations</h3>
                    <p id="recommendation-text">Maintain your current weight with a balanced diet and regular exercise.</p>
                </div>
            </div>
        </div>
        
        <div class="calculator-card">
            <h2>Understanding BMI</h2>
            <p>Body Mass Index (BMI) is a measure of body fat based on height and weight that applies to adult men and women.</p>
            
            <h3>BMI Categories:</h3>
            <ul>
                <li><strong>Underweight:</strong> BMI less than 18.5</li>
                <li><strong>Normal weight:</strong> BMI 18.5 to 24.9</li>
                <li><strong>Overweight:</strong> BMI 25 to 29.9</li>
                <li><strong>Obesity:</strong> BMI 30 or greater</li>
            </ul>
            
            <p>Note: BMI is a screening tool and does not directly measure body fat. Healthcare professionals use additional tools for diagnosis.</p>
        </div>
    </div>
    
    <div class="ads-container">
        <div class="ad-title">Advertisement</div>
        <div class="ad-placeholder">
            <!-- Google AdSense Ad Unit -->
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-YOUR_ADSENSE_ID" crossorigin="anonymous"></script>
            <ins class="adsbygoogle"
                 style="display:block"
                 data-ad-client="ca-pub-YOUR_ADSENSE_ID"
                 data-ad-slot="YOUR_AD_SLOT"
                 data-ad-format="auto"
                 data-full-width-responsive="true"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
            <p>Ad will be displayed here</p>
        </div>
        
        <div class="ad-placeholder">
            <div class="ad-title">Sponsored Content</div>
            <p>Advertisement space (300x250)</p>
            <!-- Additional AdSense code can be placed here -->
        </div>
    </div>
</div>

<footer>
    <div class="disclaimer">
        <p><strong>Disclaimer:</strong> This BMI calculator provides approximate values and should not be used as a sole indicator of health. Consult a healthcare professional for advice on weight and health.</p>
    </div>
    <p>© 2023 HealthMate BMI Calculator | Privacy Policy | Terms of Use</p>
</footer>

<script>
    // Gender selection
    const maleOption = document.getElementById('male');
    const femaleOption = document.getElementById('female');
    let selectedGender = 'male';
    
    maleOption.addEventListener('click', () => {
        maleOption.classList.add('selected');
        femaleOption.classList.remove('selected');
        selectedGender = 'male';
    });
    
    femaleOption.addEventListener('click', () => {
        femaleOption.classList.add('selected');
        maleOption.classList.remove('selected');
        selectedGender = 'female';
    });
    
    // Height unit toggle
    const heightUnitToggle = document.getElementById('heightUnitToggle');
    const heightCmInput = document.getElementById('heightCm');
    const heightInInput = document.getElementById('heightIn');
    
    heightUnitToggle.addEventListener('change', function() {
        if (this.checked) {
            heightCmInput.classList.remove('active');
            heightInInput.classList.add('active');
        } else {
            heightInInput.classList.remove('active');
            heightCmInput.classList.add('active');
        }
    });
    
    // BMI Calculation
    document.getElementById('calculate-btn').addEventListener('click', () => {
        const age = parseInt(document.getElementById('age').value);
        const weight = parseFloat(document.getElementById('weight').value);
        
        let height;
        if (heightUnitToggle.checked) {
            // Convert inches to cm for calculation
            const heightIn = parseFloat(document.getElementById('heightInInput').value);
            if (!heightIn || heightIn < 20 || heightIn > 100) {
                alert('Please enter a valid height between 20 and 100 inches');
                return;
            }
            height = heightIn * 2.54; // Convert inches to cm
        } else {
            height = parseFloat(document.getElementById('heightCmInput').value);
            if (!height || height < 50 || height > 250) {
                alert('Please enter a valid height between 50cm and 250cm');
                return;
            }
        }
        
        if (!age || age < 1 || age > 100) {
            alert('Please enter a valid age between 1 and 100');
            return;
        }
        
        if (!weight || weight < 2 || weight > 300) {
            alert('Please enter a valid weight between 2kg and 300kg');
            return;
        }
        
        // Calculate BMI: weight (kg) / (height (m) * height (m))
        const heightInMeters = height / 100;
        const bmi = weight / (heightInMeters * heightInMeters);
        const roundedBMI = bmi.toFixed(1);
        
        // Display result
        document.getElementById('bmi-value').textContent = roundedBMI;
        const resultElement = document.getElementById('result');
        resultElement.style.display = 'block';
        
        // Determine category and recommendations
        const categoryElement = document.getElementById('bmi-category');
        const recommendationElement = document.getElementById('recommendation-text');
        
        let category = '';
        let recommendation = '';
        
        if (bmi < 18.5) {
            category = 'Underweight';
            categoryElement.className = 'bmi-category underweight';
            recommendation = `For your age and gender, a BMI below 18.5 is considered underweight. Consider consulting with a healthcare provider about healthy weight gain strategies.`;
        } else if (bmi >= 18.5 && bmi < 25) {
            category = 'Normal Weight';
            categoryElement.className = 'bmi-category normal';
            recommendation = `For your age and gender, your BMI is in the healthy range. Maintain your weight with a balanced diet and regular physical activity.`;
        } else if (bmi >= 25 && bmi < 30) {
            category = 'Overweight';
            categoryElement.className = 'bmi-category overweight';
            recommendation = `For your age and gender, a BMI between 25 and 29.9 is considered overweight. Consider incorporating more physical activity and healthier food choices.`;
        } else {
            category = 'Obese';
            categoryElement.className = 'bmi-category obese';
            recommendation = `For your age and gender, a BMI of 30 or higher is considered obese. It's recommended to consult with a healthcare provider about weight management strategies.`;
        }
        
        categoryElement.textContent = category;
        recommendationElement.textContent = recommendation;
        
        // Scroll to results
        resultElement.scrollIntoView({ behavior: 'smooth' });
    });
</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions