/    Sign up×
Community /Pin to ProfileBookmark

How can I resize my font depending on browser width?

I would like to make my font size smaller if my browser width falls below a certain number. This is to make the font fit better on small screens. How can I do this? I know there’s a way in CSS, but I’m not sure how.

Thanks!
Multimediocrity

to post a comment
CSS

4 Comments(s)

Copy linkTweet thisAlerts:
@cootheadOct 11.2014 — Hi there multimediocrity,

[indent]

here is a possible solution...
[color=navy]
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">

<title>CSS vw</title>

<style media="screen">
h1 {
font-size:2.5vw;
text-align:center;
}
</style>

</head>
<body>

<h1>This text resizes according to screen width</h1>

</body>
</html>[/color]


[b]Further reading[/b]:-

[indent]https://dev.opera.com/articles/css-viewport-units/[/indent]

[/indent]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@multimediocrityauthorOct 11.2014 — Yeah, those are good solutions, but I don't get a whole lot of control with them. I think the approach I was looking for is this:

@media screen and (max-width: 500px) {

body {font-size: 10pt;}

}
Copy linkTweet thisAlerts:
@deathshadowOct 13.2014 — You are correct, media queries are the answer to what you asked -- BUT:

1) PT is for print, not screen. Use % or EM's.

2) If you set on BODY, it effects EVERYTHING -- if you have to change it on body just because of the device width, it is possible there's something horribly wrong with your layout like fonts that are too blasted large in the first place.

3) you shouldn't have to say screen if you are applying your CSS correctly by having a MEDIA attribute on your LINK... since in a well written site there is no legitimate reason to EVER use the STYLE tag. [i]Which is why I think the STYLE tag should be removed from HTML entirely and the STYLE attribute should be deprecated for all but the rarest of corner-cases.[/i]

There's a reason 99% of my layouts start out with this on BODY:

font:normal 85%/150% arial,helvetica,sans-serif;

... and I've never had the need to change the default font just because of width. Shrinking things like numbered headings (usually the only legitimate place to have larger text in the first place) sure... but for flow text?
×

Success!

Help @multimediocrity spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...