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

QR code component with self-hosted web fonts

P
Sabine•80
@SabineEmden
A solution to the QR code component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

For this challenge, I took a deep dive into web sustainability best practices for web fonts:

  • Choosing between static and variable fonts
  • Subsetting fonts to only include needed characters
  • Converting font files to the most efficient formats
  • Using the correct font-face declarations
  • Preloading font files to improve page load performance

In future projects, I want to continue using what I learnt in this challenge and explore other web sustainability best practices.

What challenges did you encounter, and how did you overcome them?

I dove deep into topics like font subsetting, converting font files, font-face declarations, and pre-loading font files. You can read about the choices I made and find links to the main resources I used in the README for this project.

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

I would appreciate feedback on the way I used web fonts, as this was my main focus for this project.

This is also my first challenge on Frontend Mentor. I want to make sure I got all the basics right and have a good foundation going forward.

Thanks for your help!

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Sabine•80
    @SabineEmden
    Posted 9 months ago

    Kagan MacTane is a web developer based in Brooklyn and San Francisco. He was so kind to give me a very thorough code review after I posted a link to my solution on Mastodon. Here are Kagan’s comments and my response.

    Kagan: "I'm not sure the div inside the footer is necessary. You can just put the div's content directly into the footer tag if you want."

    Before:

    <footer>
      <div class="attribution">
        Challenge by
         <a href="https://www.frontendmentor.io?ref=challenge" target="_blank"
         >Frontend Mentor</a
         >. Coded by
         <a href="https://www.frontendmentor.io/profile/SabineEmden"
         >Sabine Emden</a
         >.
      </div>
    </footer>
    
    .attribution {
      font-size: 0.6875rem;
      text-align: center;
    }
    .attribution a {
      color: hsl(228, 45%, 44%);
    }
    

    I agree. The div inside the footer isn't necessary. It's there because it and the styling for its attribution class were part of the starter code. But there is no rule again replacing divs with semantic HTML tags. I'll remove the div and replace the class selector in the CSS with the element selector for the footer.

    After:

    <footer>
       Challenge by
       <a href="https://www.frontendmentor.io?ref=challenge" target="_blank"
         >Frontend Mentor</a
       >. Coded by
       <a href="https://www.frontendmentor.io/profile/SabineEmden"
         >Sabine Emden</a
       >.
    </footer>
    
    footer {
      font-size: 0.6875rem;
      text-align: center;
    }
    footer a {
      color: hsl(228, 45%, 44%);
    }
    

    Kagan: "You've got some gnarly fractions going on in your font sizes. Maybe you could just set the base font size to be something a little larger or smaller, and then your decimals might be more like .5, .75, etc.? (Not sure; I haven't done the math on it and it might not be feasible.)"

    Before:

    body {
      ...
      font-size: 0.9375rem;
      ...
    }
    
    .card-qr-code h2 {
      font-size: 1.375;
      ...
    }
    
    footer {
      font-size: 0.6875rem;
      ...
    }
    

    The font sizes are 15px (0.9375rem) for the paragraph, 22px (1.375rem) for the heading, and 11px (0.6875rem) for the footer. The fractions make the code less readable. It’s difficult to tell what the font sizes are without pulling out a calculator.

    I can think of four possible solutions:

    • Change the font sizes slightly to 1rem (16px), 1.5rem (24px), and 0.75rem (12px).
    • Use the The 62.5% Font Size Trick and set the root font size to 62.5%, which is equivalent to 10px. This changes the font sizes in the design to 1.5rem, 2.2rem, and 1.1rem.
    • Leave the font sizes in rem as they are and add comments with the sizes in pixel to the style sheet.
    • Use calc() to convert the font sizes.

    I’m a hesitant to change the font sizes. I got the values for the font sizes from the style guide and the Figma files. The brief for the project is to “get it looking as close to the design as possible”, and the font sizes are part of the design.

    I’ll go with the comments. They are the simplest option, stay true to the design, and will still work if the QR code component is used as part of a bigger project.

    After:

    body {
      ...
      /* 0.9375rem = 0.9375 * 16px = 15px */
      font-size: 0.9375rem;
      ...
    }
    
    .card-qr-code h2 {
      /* 1.375rem = 1.375 * 16px = 22px */
      font-size: 1.375rem;
      ...
    }
    
    footer {
      /* 0.6875rem = 0.6875 * 16px = 11px */
      font-size: 0.6875rem;
      ...
    }
    

    Kagan: "Also, I see you're using HSL colors. I'd like to know more about that decision (I'm more used to RGB). Were you advised to use HSL? Saw that in an article or course somewhere?"

    I used HSL colors because that’s how the colors were given in the style guide for the project.

    Kagan: "Also, just gotta say, and this is totally just my own pet peeve about spelling: there's a bunch of WOOF2 instead of WOFF2. It's just in documentation and obviously doesn't affect functionality at all, but it makes me twitch. Like I said, nitpicking!"

    I totally agree! That needs to be changed. Thanks for pointing it out to me! That does not show attention to detail.

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