CSS - Roboto Font discrepancy in Chrome and Firefox

627 Views Asked by At

I have created a button and have used Roboto fonts. While testing on various browsers (chrome and firefox), I have noticed that the text appears to be different.

The problem occurs when I use font-weight: bold.

CHROME: This is what the font looks like on chrome

FIREFOX: This is what it the font looks like on firefox

This is what the CSS looks like.

.yellow-button {
  width: 91%;
  height: 48px;
  background: rgba(255, 212, 0, 1);
  opacity: 1;
  position: absolute;
  top: 109px;
  left: 0;
  right: 0;
  margin-left: auto !important;
  margin-right: auto !important;
  border-radius: 10px;
  box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.03999999910593033);
  overflow: hidden;
}

.button-text {
  width: fit-content;
  color: rgba(55, 4, 63, 1);
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
  margin-left: auto !important;
  margin-right: auto !important;
  font-family: Roboto;
  font-weight: Bold;
  font-size: 18px;
  opacity: 1;
  text-align: center;
}
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet" />
<button class="yellow-button">
    <span class="button-text">Hello world test 123</span>
</button>

1

There are 1 best solutions below

2
On

Browsers have some predefined CSS set which may vary. To make sure that pages look the same on all browsers, it a good practice to use a CSS-reset/CSS-reboot code which sets every CSS back to zero. All front-end frameworks use CSS-reboot and then add their own CSS on top of it. It will be looking somewhat like this:

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
html, body {
    height: 100vh;
    min-height: 100vh;
}

To learn more about CSS-reset, you can have a look here: CSS-reboot and CSS-resets