Converting px to em - text becomes smaller than original
up vote
-3
down vote
favorite
Currently in the final stages of building a new website and have recently ran an accessibility checker. The checker is recommending changing my font sizes from px to em.
However when I do a straight forward conversion (16px to 1em) the font becomes really small. Am I missing something?
Here is my styling.
.bodyText {font-size: 16px !important; padding-top: 10px; margin-bottom: 20px;}
.bodyText a {color: #008080 !important; text-decoration: underline;}
.bodyText a:hover {color: #008080 !important;}
.bodyText li {font-size: 16px !important; color: #686868;}
.bodyText p {font-size: 16px !important; color: #686868;}
.bodyText p strong {color: #333333;}
All of this also sits in the body which has this attached.
body {font-size: 16px !important; font-family: "Source Sans Pro", sans-serif !important; font-style: normal; font-weight: normal;}
tbody {font-size: 16px !important; font-family: "Source Sans Pro", sans-serif !important; font-style: normal; font-weight: normal;}
html css
|
show 2 more comments
up vote
-3
down vote
favorite
Currently in the final stages of building a new website and have recently ran an accessibility checker. The checker is recommending changing my font sizes from px to em.
However when I do a straight forward conversion (16px to 1em) the font becomes really small. Am I missing something?
Here is my styling.
.bodyText {font-size: 16px !important; padding-top: 10px; margin-bottom: 20px;}
.bodyText a {color: #008080 !important; text-decoration: underline;}
.bodyText a:hover {color: #008080 !important;}
.bodyText li {font-size: 16px !important; color: #686868;}
.bodyText p {font-size: 16px !important; color: #686868;}
.bodyText p strong {color: #333333;}
All of this also sits in the body which has this attached.
body {font-size: 16px !important; font-family: "Source Sans Pro", sans-serif !important; font-style: normal; font-weight: normal;}
tbody {font-size: 16px !important; font-family: "Source Sans Pro", sans-serif !important; font-style: normal; font-weight: normal;}
html css
1
Please share your markup
– Shahar Shukrani
Nov 22 at 16:22
1
Please edit your question to include all the code needed to demonstrate your issue include HTML and CSS. Use a snippet (CTRL-M when you edit) stackoverflow.com/help/mcve
– Mark Schultheiss
Nov 22 at 16:25
1
16 px is NOT 1em - well it CAN be, it can also be 2px or 200px it is just different.
– Mark Schultheiss
Nov 22 at 16:26
Sorry, edited to show my css styling.
– HannahM
Nov 22 at 16:33
AND the markup please. Also as soon as you start using!important
(nearly always a bad idea) things get really messy to edit and manage.
– Mark Schultheiss
Nov 22 at 16:37
|
show 2 more comments
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
Currently in the final stages of building a new website and have recently ran an accessibility checker. The checker is recommending changing my font sizes from px to em.
However when I do a straight forward conversion (16px to 1em) the font becomes really small. Am I missing something?
Here is my styling.
.bodyText {font-size: 16px !important; padding-top: 10px; margin-bottom: 20px;}
.bodyText a {color: #008080 !important; text-decoration: underline;}
.bodyText a:hover {color: #008080 !important;}
.bodyText li {font-size: 16px !important; color: #686868;}
.bodyText p {font-size: 16px !important; color: #686868;}
.bodyText p strong {color: #333333;}
All of this also sits in the body which has this attached.
body {font-size: 16px !important; font-family: "Source Sans Pro", sans-serif !important; font-style: normal; font-weight: normal;}
tbody {font-size: 16px !important; font-family: "Source Sans Pro", sans-serif !important; font-style: normal; font-weight: normal;}
html css
Currently in the final stages of building a new website and have recently ran an accessibility checker. The checker is recommending changing my font sizes from px to em.
However when I do a straight forward conversion (16px to 1em) the font becomes really small. Am I missing something?
Here is my styling.
.bodyText {font-size: 16px !important; padding-top: 10px; margin-bottom: 20px;}
.bodyText a {color: #008080 !important; text-decoration: underline;}
.bodyText a:hover {color: #008080 !important;}
.bodyText li {font-size: 16px !important; color: #686868;}
.bodyText p {font-size: 16px !important; color: #686868;}
.bodyText p strong {color: #333333;}
All of this also sits in the body which has this attached.
body {font-size: 16px !important; font-family: "Source Sans Pro", sans-serif !important; font-style: normal; font-weight: normal;}
tbody {font-size: 16px !important; font-family: "Source Sans Pro", sans-serif !important; font-style: normal; font-weight: normal;}
html css
html css
edited Nov 22 at 16:32
asked Nov 22 at 16:17
HannahM
32
32
1
Please share your markup
– Shahar Shukrani
Nov 22 at 16:22
1
Please edit your question to include all the code needed to demonstrate your issue include HTML and CSS. Use a snippet (CTRL-M when you edit) stackoverflow.com/help/mcve
– Mark Schultheiss
Nov 22 at 16:25
1
16 px is NOT 1em - well it CAN be, it can also be 2px or 200px it is just different.
– Mark Schultheiss
Nov 22 at 16:26
Sorry, edited to show my css styling.
– HannahM
Nov 22 at 16:33
AND the markup please. Also as soon as you start using!important
(nearly always a bad idea) things get really messy to edit and manage.
– Mark Schultheiss
Nov 22 at 16:37
|
show 2 more comments
1
Please share your markup
– Shahar Shukrani
Nov 22 at 16:22
1
Please edit your question to include all the code needed to demonstrate your issue include HTML and CSS. Use a snippet (CTRL-M when you edit) stackoverflow.com/help/mcve
– Mark Schultheiss
Nov 22 at 16:25
1
16 px is NOT 1em - well it CAN be, it can also be 2px or 200px it is just different.
– Mark Schultheiss
Nov 22 at 16:26
Sorry, edited to show my css styling.
– HannahM
Nov 22 at 16:33
AND the markup please. Also as soon as you start using!important
(nearly always a bad idea) things get really messy to edit and manage.
– Mark Schultheiss
Nov 22 at 16:37
1
1
Please share your markup
– Shahar Shukrani
Nov 22 at 16:22
Please share your markup
– Shahar Shukrani
Nov 22 at 16:22
1
1
Please edit your question to include all the code needed to demonstrate your issue include HTML and CSS. Use a snippet (CTRL-M when you edit) stackoverflow.com/help/mcve
– Mark Schultheiss
Nov 22 at 16:25
Please edit your question to include all the code needed to demonstrate your issue include HTML and CSS. Use a snippet (CTRL-M when you edit) stackoverflow.com/help/mcve
– Mark Schultheiss
Nov 22 at 16:25
1
1
16 px is NOT 1em - well it CAN be, it can also be 2px or 200px it is just different.
– Mark Schultheiss
Nov 22 at 16:26
16 px is NOT 1em - well it CAN be, it can also be 2px or 200px it is just different.
– Mark Schultheiss
Nov 22 at 16:26
Sorry, edited to show my css styling.
– HannahM
Nov 22 at 16:33
Sorry, edited to show my css styling.
– HannahM
Nov 22 at 16:33
AND the markup please. Also as soon as you start using
!important
(nearly always a bad idea) things get really messy to edit and manage.– Mark Schultheiss
Nov 22 at 16:37
AND the markup please. Also as soon as you start using
!important
(nearly always a bad idea) things get really messy to edit and manage.– Mark Schultheiss
Nov 22 at 16:37
|
show 2 more comments
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
First of all let me say that EM is used locally and REM is used globally what do i mean with that?
Rem uses the html tag font-size so if:
html {
font-size: 16px;
}
Then the 1 rem
is equal to 16px
On the other hand when you use em
you need to be context aware, meaning that if the parent container of the text element got font-size: 12px
the 1em
becomes 12px
You can read more about it here: https://j.eremy.net/confused-about-rem-and-em/
"1 rem is equal to 16px" - depends on the browser, most but not all.
– Mark Schultheiss
Nov 22 at 16:29
Read the link i shared. rem is read from html root tag, so as long if you define html to have font-size 16px then its 16 px. So i some obscure browser implements something else then override it with html fontsize 16
– Nopzen
Nov 22 at 16:33
I think this might be my problem, I have no font size included in the html tag.
– HannahM
Nov 22 at 16:35
Here is the actual specification if you want to have a definitive source w3.org/Style/CSS/specs.en.html
– Mark Schultheiss
Nov 22 at 16:36
This solved the problem - thank you. I set my font-size in the html (originally as pixels but this also resulted in accessibility errors) as 100%, then I set the rest of my fonts throughout the site in em. All looks great and passes the accessibility check. Thanks for your help.
– HannahM
Nov 23 at 11:47
add a comment |
up vote
0
down vote
So em is not a size like px is. em refers to the current font-size set on an item,
so if
p {
font-size: 16px;
}
then when you add in the em to a certain piece like say you have
<p class="em-class">Hello World</p>
<style>
.em-class {
font-size: 2em;
}
</style>
then your font-size would be 32px on that class. It essentially works as a % of the current font-size
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
First of all let me say that EM is used locally and REM is used globally what do i mean with that?
Rem uses the html tag font-size so if:
html {
font-size: 16px;
}
Then the 1 rem
is equal to 16px
On the other hand when you use em
you need to be context aware, meaning that if the parent container of the text element got font-size: 12px
the 1em
becomes 12px
You can read more about it here: https://j.eremy.net/confused-about-rem-and-em/
"1 rem is equal to 16px" - depends on the browser, most but not all.
– Mark Schultheiss
Nov 22 at 16:29
Read the link i shared. rem is read from html root tag, so as long if you define html to have font-size 16px then its 16 px. So i some obscure browser implements something else then override it with html fontsize 16
– Nopzen
Nov 22 at 16:33
I think this might be my problem, I have no font size included in the html tag.
– HannahM
Nov 22 at 16:35
Here is the actual specification if you want to have a definitive source w3.org/Style/CSS/specs.en.html
– Mark Schultheiss
Nov 22 at 16:36
This solved the problem - thank you. I set my font-size in the html (originally as pixels but this also resulted in accessibility errors) as 100%, then I set the rest of my fonts throughout the site in em. All looks great and passes the accessibility check. Thanks for your help.
– HannahM
Nov 23 at 11:47
add a comment |
up vote
0
down vote
accepted
First of all let me say that EM is used locally and REM is used globally what do i mean with that?
Rem uses the html tag font-size so if:
html {
font-size: 16px;
}
Then the 1 rem
is equal to 16px
On the other hand when you use em
you need to be context aware, meaning that if the parent container of the text element got font-size: 12px
the 1em
becomes 12px
You can read more about it here: https://j.eremy.net/confused-about-rem-and-em/
"1 rem is equal to 16px" - depends on the browser, most but not all.
– Mark Schultheiss
Nov 22 at 16:29
Read the link i shared. rem is read from html root tag, so as long if you define html to have font-size 16px then its 16 px. So i some obscure browser implements something else then override it with html fontsize 16
– Nopzen
Nov 22 at 16:33
I think this might be my problem, I have no font size included in the html tag.
– HannahM
Nov 22 at 16:35
Here is the actual specification if you want to have a definitive source w3.org/Style/CSS/specs.en.html
– Mark Schultheiss
Nov 22 at 16:36
This solved the problem - thank you. I set my font-size in the html (originally as pixels but this also resulted in accessibility errors) as 100%, then I set the rest of my fonts throughout the site in em. All looks great and passes the accessibility check. Thanks for your help.
– HannahM
Nov 23 at 11:47
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
First of all let me say that EM is used locally and REM is used globally what do i mean with that?
Rem uses the html tag font-size so if:
html {
font-size: 16px;
}
Then the 1 rem
is equal to 16px
On the other hand when you use em
you need to be context aware, meaning that if the parent container of the text element got font-size: 12px
the 1em
becomes 12px
You can read more about it here: https://j.eremy.net/confused-about-rem-and-em/
First of all let me say that EM is used locally and REM is used globally what do i mean with that?
Rem uses the html tag font-size so if:
html {
font-size: 16px;
}
Then the 1 rem
is equal to 16px
On the other hand when you use em
you need to be context aware, meaning that if the parent container of the text element got font-size: 12px
the 1em
becomes 12px
You can read more about it here: https://j.eremy.net/confused-about-rem-and-em/
edited Nov 22 at 19:06
Temani Afif
62.8k93574
62.8k93574
answered Nov 22 at 16:28
Nopzen
208313
208313
"1 rem is equal to 16px" - depends on the browser, most but not all.
– Mark Schultheiss
Nov 22 at 16:29
Read the link i shared. rem is read from html root tag, so as long if you define html to have font-size 16px then its 16 px. So i some obscure browser implements something else then override it with html fontsize 16
– Nopzen
Nov 22 at 16:33
I think this might be my problem, I have no font size included in the html tag.
– HannahM
Nov 22 at 16:35
Here is the actual specification if you want to have a definitive source w3.org/Style/CSS/specs.en.html
– Mark Schultheiss
Nov 22 at 16:36
This solved the problem - thank you. I set my font-size in the html (originally as pixels but this also resulted in accessibility errors) as 100%, then I set the rest of my fonts throughout the site in em. All looks great and passes the accessibility check. Thanks for your help.
– HannahM
Nov 23 at 11:47
add a comment |
"1 rem is equal to 16px" - depends on the browser, most but not all.
– Mark Schultheiss
Nov 22 at 16:29
Read the link i shared. rem is read from html root tag, so as long if you define html to have font-size 16px then its 16 px. So i some obscure browser implements something else then override it with html fontsize 16
– Nopzen
Nov 22 at 16:33
I think this might be my problem, I have no font size included in the html tag.
– HannahM
Nov 22 at 16:35
Here is the actual specification if you want to have a definitive source w3.org/Style/CSS/specs.en.html
– Mark Schultheiss
Nov 22 at 16:36
This solved the problem - thank you. I set my font-size in the html (originally as pixels but this also resulted in accessibility errors) as 100%, then I set the rest of my fonts throughout the site in em. All looks great and passes the accessibility check. Thanks for your help.
– HannahM
Nov 23 at 11:47
"1 rem is equal to 16px" - depends on the browser, most but not all.
– Mark Schultheiss
Nov 22 at 16:29
"1 rem is equal to 16px" - depends on the browser, most but not all.
– Mark Schultheiss
Nov 22 at 16:29
Read the link i shared. rem is read from html root tag, so as long if you define html to have font-size 16px then its 16 px. So i some obscure browser implements something else then override it with html fontsize 16
– Nopzen
Nov 22 at 16:33
Read the link i shared. rem is read from html root tag, so as long if you define html to have font-size 16px then its 16 px. So i some obscure browser implements something else then override it with html fontsize 16
– Nopzen
Nov 22 at 16:33
I think this might be my problem, I have no font size included in the html tag.
– HannahM
Nov 22 at 16:35
I think this might be my problem, I have no font size included in the html tag.
– HannahM
Nov 22 at 16:35
Here is the actual specification if you want to have a definitive source w3.org/Style/CSS/specs.en.html
– Mark Schultheiss
Nov 22 at 16:36
Here is the actual specification if you want to have a definitive source w3.org/Style/CSS/specs.en.html
– Mark Schultheiss
Nov 22 at 16:36
This solved the problem - thank you. I set my font-size in the html (originally as pixels but this also resulted in accessibility errors) as 100%, then I set the rest of my fonts throughout the site in em. All looks great and passes the accessibility check. Thanks for your help.
– HannahM
Nov 23 at 11:47
This solved the problem - thank you. I set my font-size in the html (originally as pixels but this also resulted in accessibility errors) as 100%, then I set the rest of my fonts throughout the site in em. All looks great and passes the accessibility check. Thanks for your help.
– HannahM
Nov 23 at 11:47
add a comment |
up vote
0
down vote
So em is not a size like px is. em refers to the current font-size set on an item,
so if
p {
font-size: 16px;
}
then when you add in the em to a certain piece like say you have
<p class="em-class">Hello World</p>
<style>
.em-class {
font-size: 2em;
}
</style>
then your font-size would be 32px on that class. It essentially works as a % of the current font-size
add a comment |
up vote
0
down vote
So em is not a size like px is. em refers to the current font-size set on an item,
so if
p {
font-size: 16px;
}
then when you add in the em to a certain piece like say you have
<p class="em-class">Hello World</p>
<style>
.em-class {
font-size: 2em;
}
</style>
then your font-size would be 32px on that class. It essentially works as a % of the current font-size
add a comment |
up vote
0
down vote
up vote
0
down vote
So em is not a size like px is. em refers to the current font-size set on an item,
so if
p {
font-size: 16px;
}
then when you add in the em to a certain piece like say you have
<p class="em-class">Hello World</p>
<style>
.em-class {
font-size: 2em;
}
</style>
then your font-size would be 32px on that class. It essentially works as a % of the current font-size
So em is not a size like px is. em refers to the current font-size set on an item,
so if
p {
font-size: 16px;
}
then when you add in the em to a certain piece like say you have
<p class="em-class">Hello World</p>
<style>
.em-class {
font-size: 2em;
}
</style>
then your font-size would be 32px on that class. It essentially works as a % of the current font-size
answered Nov 22 at 16:31
Nick Beall
112
112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434891%2fconverting-px-to-em-text-becomes-smaller-than-original%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Please share your markup
– Shahar Shukrani
Nov 22 at 16:22
1
Please edit your question to include all the code needed to demonstrate your issue include HTML and CSS. Use a snippet (CTRL-M when you edit) stackoverflow.com/help/mcve
– Mark Schultheiss
Nov 22 at 16:25
1
16 px is NOT 1em - well it CAN be, it can also be 2px or 200px it is just different.
– Mark Schultheiss
Nov 22 at 16:26
Sorry, edited to show my css styling.
– HannahM
Nov 22 at 16:33
AND the markup please. Also as soon as you start using
!important
(nearly always a bad idea) things get really messy to edit and manage.– Mark Schultheiss
Nov 22 at 16:37