Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 9 months ago

BMI Calculator using TypeScript & Tailwind

accessibility, tailwind-css, typescript, vite
P
Dan Marius•1,275
@danmlarsen
A solution to the Body Mass Index calculator challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What specific areas of your project would you like help with?

I appreciate any helpful feedback.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Ibrahim Mohammed•640
    @MohammedOnGit
    Posted 9 months ago

    Hello Dan Marius!

    Your HTML structure for the Body Mass Index Calculator looks well-organized and structured for a responsive and interactive page. Here are a few suggestions and best practices to improve your code:

    1. Improve Form Accessibility Add aria-label attributes or descriptive labels where necessary to enhance accessibility. For instance, for the radio buttons, you can explicitly associate labels and improve accessibility for screen readers:
    <input class="accent-blue size-[1.9375rem]" type="radio" name="units" id="units_metric" value="metric" aria-label="Use Metric units" checked />
    <input class="accent-blue size-[1.9375rem]" type="radio" name="units" id="units_imperial" value="imperial" aria-label="Use Imperial units" />
    
    
    1. Input Types In the input elements for height and weight, the name attribute should be unique and reflective of the field. You currently have multiple fields with name="height"; you should change them to ensure each field has a distinct name:
    <input type="number" name="height_metric" id="height_primary" ... />
    <input type="number" name="height_imperial" id="height_secondary" ... />
    <input type="number" name="weight_metric" id="weight_primary" ... />
    <input type="number" name="weight_imperial" id="weight_secondary" ... />
    
    1. Use for Attributes in Labels Ensure that all labels use the for attribute to associate them with their corresponding form elements for better form accessibility:
    <label for="units_metric">Metric</label>
    <label for="units_imperial">Imperial</label>
    
    1. Viewport Consistency In responsive design, ensure the image sizes are well-scaled for different devices. Using relative units (vw, vh, em, or rem) instead of fixed sizes (px) for widths and heights could improve adaptability.

    2. Input Validation If you’re expecting specific input ranges (e.g., minimum and maximum height or weight), it’s helpful to add HTML validation by setting min, max, and step attributes:

    <input type="number" name="height_metric" id="height_primary" min="0" max="300" step="0.1" ... />
    <input type="number" name="weight_metric" id="weight_primary" min="0" max="300" step="0.1" ... />
    
    1. Alt Text for Decorative Images For decorative images (like pattern-curved-line-left.svg), the alt attribute should be set to an empty string ("") to ensure screen readers skip them:
    <img src="/images/pattern-curved-line-left.svg" alt="" />
    

    Overall, your structure looks solid, and following these best practices will ensure better accessibility, usability, and performance of your BMI Calculator.

    Marked as helpful

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit 1st-party linked stylesheets, and styles within <style> tags.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub