You can use em, %, px. But in combination with media-queriesSee this Link to learn about media-queries. Also, CSS3 have some new values for sizing things relative to the current viewport size: vw, vh, and vmin. See link about that.
@media screen and (max-width : 320px)
{
body or yourdiv element
{
font:<size>px/em/rm;
}
}
@media screen and (max-width : 1204px)
{
body or yourdiv element
{
font:<size>px/em/rm;
}
}
You can give it manually according to screen size of screen.Just have a look of different screen size and add manually the font size.
I've developed a nice JS solution - which is suitable for entirely-responsive HTML (i.e. HTML built with percentages)
I use only "em" to define font-sizes.
html font size is set to 10 pixels:
html {
font-size: 100%;
font-size: 62.5%;
}
I call a font-resizing function on document-ready:
// this requires JQuery
function doResize() {
// FONT SIZE
var ww = $('body').width();
var maxW = [your design max-width here];
ww = Math.min(ww, maxW);
var fw = ww*(10/maxW);
var fpc = fw*100/16;
var fpc = Math.round(fpc*100)/100;
$('html').css('font-size',fpc+'%');
}
Use dimensions in % or rem. Just change the base font size everything will change. Unlike previous one you could just change the body font and not h1 everytime or let base font size to default of the device and rest all in em.
“Root Ems”(rem): The “rem” is a scalable unit. 1rem is equal to the font-size of the body/html, for instance, if the font-size of the document is 12pt, 1em is equal to 12pt. Root Ems are scalable in nature, so 2em would equal 24pt, .5em would equal 6pt, etc..
Percent (%): The percent unit is much like the “em” unit, save for a few fundamental differences. First and foremost, the current font-size is equal to 100% (i.e. 12pt = 100%). While using the percent unit, your text remains fully scalable for mobile devices and for accessibility.
where you can set min and max text size in relation of min and max size of box that you want "check" size. In addition you can check size of dom element different than box where you want apply text size.
You resize text between 19px and 25px on #size-2 element, based on 500px and 960px width of #size-2 element
resizeTextInRange(500,960,19,25,'#size-2');
You resize text between 13px and 20px on #size-1 element, based on 500px and 960px width of body element