Spacer in Android Jetpack Compose Last Updated : 04 May, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In Jetpack Compose, a Spacer is a blank element that is used to create a Space between two UI elements. Suppose, we have created Element 1 and we want to place Element 2 below Element 1 but with a top margin, we can declare a Spacer between the two elements. So in this article, we will show you how you could implement a Spacer in Android using Jetpack Compose. Follow the below steps once the IDE is ready.Step by Step ImplementationStep 1: Create a New Project in Android StudioTo create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.While choosing the template, select Empty Compose Activity or Empty Activity. If you do not find this template, try upgrading the Android Studio to the latest version.Step 2: Working with the MainActivity.kt fileGo to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.MainActivity.kt: Kotlin package com.geeksforgeeks.demo import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.* import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.* import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.* class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MaterialTheme { SpacerDemonstration() } } } } // create a composable function @Composable fun SpacerDemonstration(){ Column( Modifier.fillMaxWidth().absolutePadding(10.dp, 100.dp, 10.dp, 0.dp), horizontalAlignment = Alignment.CenterHorizontally) { // Creating Button 1 Button(onClick = { /*TODO*/ }, colors = ButtonDefaults.buttonColors(containerColor = Color(0XFF0F9D58)), ) { Text("Button 1", color = Color.White) } // Adding a Spacer of height 20dp Spacer(modifier = Modifier.height(20.dp)) // Creating Button 2 Button(onClick = { /*TODO*/ }, colors = ButtonDefaults.buttonColors(containerColor = Color(0XFF0F9D58)), ) { Text("Button 2", color = Color.White) } // Adding a Spacer of height 200dp Spacer(modifier = Modifier.height(200.dp)) // Adding a Text Text(text = "Hello Geek!", fontSize = 50.sp) } } Output:You can see that Button 1 and Button 2 are separated by 20dp and Button 2 and Text are separated by 200dp. Comment More infoAdvertise with us Next Article Android Jetpack Compose Internal Storage A aashaypawar Follow Improve Article Tags : Kotlin Android-Jetpack Similar Reads Toast in Android Jetpack Compose In Android, a Toast is a message or a pop-up message that generally appears at the bottom of the screen for a short span. A Toast is used to deliver simple feedback about any function or operation the application is running on the device. In simpler words, it displays the status of any running or fi 2 min read SmsManager in Android using Jetpack Compose Many times while building an android application we have to add a feature through which users will be able to directly send SMS from our android application. So in this article, we will take a look at How to send a text message over a phone using SMS Manager in Android using Jetpack Compose. A sampl 6 min read Android Jetpack Compose Internal Storage Many times in the android application we have to save the data from our android application within the device storage. For storing the data we can store it in shared preferences, internal as well as external storage. In this article, we will take a look at How to save data to Internal storage in And 6 min read Date Picker in Android using Jetpack Compose In Android, a Date Picker is a widget used to select a date from the calendar. When a Date Picker is implemented in an application, the user can select a year, a month, and a day, combining to form date from a calendar-like-looking box. This data is generally needed and collected in applications tha 2 min read Services in Android using Jetpack Compose Services in Android applications are used to perform some background tasks within android applications. We can call the service to perform a specific task in the background of our application. That task will be performed continuously if our application is not visible to the user. Services are genera 6 min read Time Picker in Android using Jetpack Compose In Android, a Time Picker is a modern UI element, used in applications like Alarm and Reminders, that requires users to select a particular time for performing a particular task. It is a user interface control for selecting the time in either 24-hour format or 12-hour (AM/PM) mode. In this article, 3 min read Like