Ray Acevedo
2 min readJul 14, 2015

Android SP vs DP

First what do they stand for?

sp stands for scale-independent pixels.

dp or dip (just use dp in your code if you’re cool) stands for density-independent pixels.

What is the difference between the two?

None!

They both have 160 units per square inch, they are both density independent, and neither have the same physical size on different screens.

So, when should you use sp and when you should you use dp?

Use sp for text size…because but it is scaled by the user’s font size preference.

Use dp for everything else.

Example:

<TextView

android:layout_width=”match_parent”

android:layout_height=”wrap_content”

android:text=”Hello, world!”

android:textSize=”30sp”

android:padding=”15dp”/>

<Button

android:layout_width=”40dp”

android:layout_height=”wrap_content”

android:layout_marginLeft=“20dp”/>

More technical:

From the Android Developers Center:

DP: A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way. The density- independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a “medium” density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application’s UI, to ensure proper display of your UI on screens with different densities.

SP — this is like the dp unit, but it is also scaled by the user’s font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user’s preference.

Still confused?

Sorry, I tried my best.