Take the 2-minute tour ×

I'd like to set the font size I'm using in a WebView to a specific pixel size. I'm doing something along the lines of

<p style="font-size: 18px">Text</p>

However, the size of the font is different on different devices. Any idea how to make this work?


share|improve this question
because different devices have different sized pixels... If you actually want to set it to pixels you should be expecting this variation across devices. Do you have a specific reason for wanting to use pixels? –  FoamyGuy Oct 1 '12 at 13:18
sorry, maybe i should've elaborated on this. i use pixels, but i scale the pixels to match the device's dpi. my client has a fixed pixel design that i scale to the maximum possible size (with borders top bottom or left right). everything works perfectly except for the webview. –  Joris Weimar Oct 2 '12 at 5:50
add comment

3 Answers

up vote 3 down vote accepted

The solution I found was adding the following meta tag to the HTML

 <meta name=\"viewport\" content=\"target-densitydpi=device-dpi\" />
share|improve this answer
add comment

you can use the web view to get a settings object and setDefaultFontSize(int size) method to set the default font size.


official documentation link: https://developer.android.com/reference/android/webkit/WebSettings.html#setDefaultFontSize(int)

Alternatively, You can use setInitialScale(int percentage) method on your web view to set the percentage zoom you need.

for example:


you can try it with different percentages and see which one you like.

here's the official documentation link to help you out: https://developer.android.com/reference/android/webkit/WebView.html#setInitialScale(int)

you can also use the web view to get it's settings object and then use setBuiltInZoomControls(boolean value) method to allow/disallow the user to use the default zoom controls so they can zoom according to their preference.

for example: myWebView.getSettings().setBuiltInZoomControls(true);

here's the official documentation for this: https://developer.android.com/reference/android/webkit/WebSettings.html#setBuiltInZoomControls(boolean)

share|improve this answer
Please mark it as accepted answer if you agree with it. Thanks. –  Anup Cowkur Oct 3 '12 at 10:04
add comment

None of that was working for me, I needed to do this instead:

WebSettings settings = wv.getSettings();
if (Utils.hasIceCreamSandwich())
    settings.setTextZoom( (int)(settings.getTextZoom() * 1.2));
else {
share|improve this answer
add comment

Your Answer


