How to Use the Vuetify Text Field Component
![How to Use the Vuetify Text Field Component](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2FArtboard-1-2.png&w=3840&q=75)
Text fields are the most common way of accepting text input in a UI. They can collect user information like emails, addresses, phone numbers, etc. Let's see how we can use them in Vuetify.
The v-text-field Component
We create text fields in Vuetify with the v-text-field
component:
<template>
<v-app>
<v-row justify="center" class="ma-2">
<v-col cols="4"><v-text-field label="Regular"></v-text-field></v-col>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
![A regular Vuetify text field.](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-10.png&w=3840&q=75)
![Focusing on a regular Vuetify text field.](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-11.png&w=3840&q=75)
Vuetify Text Field Placeholders
We can indicate an expected value for the text field with the placeholder
prop:
<template>
<v-app>
<v-row justify="center" class="ma-2">
<v-col cols="4"
><v-text-field label="Regular" placeholder="Placeholder"></v-text-field
></v-col>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
![A Vuetify text field with a placeholder.](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-12.png&w=3840&q=75)
Customizing Text Field Colors in Vuetify
We can customize the color of text fields by setting the color
prop to a color in the Material Design palette:
<template>
<v-app>
<v-row justify="center" class="ma-2">
<v-col cols="4"
><v-text-field
label="Username"
color="green"
></v-text-field
></v-col>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
![A Vuetify text field with the colour customized.](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-13.png&w=3840&q=75)
Vuetify Text Field Filled Variant
We can use the filled variant of the text field with the filled
prop:
<template>
<v-app>
<v-row justify="center" class="ma-2">
<v-col cols="4"
><v-text-field label="Filled" filled></v-text-field
></v-col>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
![Vuetify text field filled variant](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-14.png&w=3840&q=75)
Vuetify Text Field Outlined Variant
Setting the outlined
prop to true on the text field component will use its outlined variant:
<template>
<v-app>
<v-row justify="center" class="ma-2">
<v-col cols="4"
><v-text-field label="Outlined" outlined></v-text-field
></v-col>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
![Vuetify text field outlined variant.](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-16.png&w=3840&q=75)
Vuetify Shaped Text Fields
Text fields with the shaped
prop have an increased border radius for the top two corners:
<template>
<v-app>
<v-row class="ma-2">
<v-col cols="6"
><v-text-field label="First Name" filled shaped></v-text-field
></v-col>
<v-col cols="6"
><v-text-field label="Last Name" outlined shaped></v-text-field
></v-col>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
![Vuetify shaped text fields.](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-20.png&w=3840&q=75)
Disabling Text Fields in Vuetify
We can stop a text field from accepting any input by setting the disabled
prop to true
.
<template>
<v-app>
<v-row class="ma-2">
<v-col cols="4"
><v-text-field label="Address" disabled></v-text-field
></v-col>
<v-col cols="4"
><v-text-field label="Address" filled disabled></v-text-field
></v-col>
<v-col cols="4"
><v-text-field label="Address" outlined disabled></v-text-field
></v-col>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
![Disabling text fields in Vuetify](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-21.png&w=3840&q=75)
Readonly Text Fields
We can also prevent text field input with the readonly
prop:
<template>
<v-app>
<v-row class="ma-2" justify="center">
<v-col cols="4"
><v-text-field label="Regular" value="Regular" readonly></v-text-field
></v-col>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
Solo Text Fields
We can style text fields with an alternative solo design with the solo
prop:
<template>
<v-app>
<v-row class="ma-2" justify="center">
<v-col cols="4"
><v-text-field
label="Solo"
solo
></v-text-field
></v-col>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
![Vuetify solo text fields](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-22.png&w=3840&q=75)
![Focusing on a Vuetify solo text fields.](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-23.png&w=3840&q=75)
Single-line Text Fields
To prevent text field labels from floating when focused, we can use the single-line
prop:
<template>
<v-app>
<v-row class="ma-2" justify="center">
<v-col cols="4"
><v-text-field label="Single-line" single-line></v-text-field
></v-col>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
![](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-24.png&w=3840&q=75)
![](/_next/image?url=https%3A%2F%2Fwp.codingbeautydev.com%2Fwp-content%2Fuploads%2F2022%2F02%2Fimage-25.png&w=3840&q=75)
Summary
Vuetify provides the v-text-field
component for creating text fields, which are useful for getting text input from users.