JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

How to Create Buttons with Vuetify

--

Buttons are one of those elements you find in just about every UI. They are the most usual way of adding interactivity to an application. Vuetify provides the v-btn component for creating buttons. Let's see the different ways in which we can use this component in a sample Vue.js application.

Regular Buttons

Here, we’ve created three evenly spaced buttons of different colours. One way of setting the colour of most components in Vuetify is with the color prop. For the green button, we add the dark property to make its text white.

<template>
<v-app>
<v-row class="ma-4 justify-space-around">
<v-btn>Button</v-btn>
<v-btn color="red">Button</v-btn>
<v-btn color="green" dark>Button</v-btn>
</v-row>
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>

Block Buttons

We create block buttons by setting the block prop to true:

<template>
<v-app>
<v-row class="ma-4">
<v-btn block>Block Button</v-btn>
</v-row>
</v-app>
</template>
...

This makes the button extend to its full available width:

Depressed Buttons

Using the depressed prop to make a button depressed removes the box-shadow:

<template>
<v-app>
<v-row class="ma-4 justify-space-around">
<v-btn depressed>Depressed Button</v-btn>
<v-btn depressed color="yellow">Depressed Button</v-btn>
<v-btn depressed color="red">Depressed Button</v-btn>
</v-row>
</v-app>
</template>
...

Beautify with Vuetify

The complete guide to creating elegant web apps with the Vuetify Material Design framework.

Download a free copy here!

Icon Buttons

We are not limited to just text, we can also create icon buttons in Vuetify. The icon prop makes the button rounded, and applies the same styles that would be applied if we set the text prop (more on this prop later in this post).

<template>
<v-app>
<v-row class="ma-4 justify-space-around">
<v-btn color="blue" icon><v-icon>mdi-thumb-up</v-icon></v-btn>
<v-btn color="red" icon><v-icon>mdi-heart</v-icon></v-btn>
<v-btn color="yellow" icon><v-icon>mdi-star</v-icon></v-btn>
</v-row>
</v-app>
</template>
...

Outlined Buttons

We can create outlined buttons with the outlined prop. These type of buttons inherit their borders from the current colour applied:

<template>
<v-app>
<v-row class="ma-4 justify-space-around">
<v-btn outlined>Outlined Button</v-btn>
<v-btn color="green" outlined>Outlined Button</v-btn>
<v-btn color="orange" outlined>Outlined Button</v-btn>
</v-row>
</v-app>
</template>
...

Plain Buttons

Plain buttons are created with the plain prop. They have a low baseline opacity that increases when you hover or focus on them:

<template>
<v-app>
<v-row class="ma-4 justify-space-around">
<v-btn plain>Plain Button</v-btn>
<v-btn color="red" plain>Plain Button</v-btn>
<v-btn color="blue" plain>Plain Button</v-btn>
</v-row>
</v-app>
</template>
...

Rounded Buttons

Using the rounded prop, we can create buttons that behave the same as regular buttons, but have rounded edges:

<template>
<v-app>
<v-row class="ma-4 justify-space-around">
<v-btn rounded>Rounded Button</v-btn>
<v-btn rounded color="blue">Rounded Button</v-btn>
<v-btn rounded color="green">Rounded Button</v-btn>
</v-row>
</v-app>
</template>
...

Text Buttons

Text buttons, created with the text prop, have no box-shadow and no background. The container for the button is only shown on hover, and the colour set for the button is applied to its text instead of its background:

<template>
<v-app>
<v-row class="ma-4" justify="space-around">
<v-btn text> Normal </v-btn>
<v-btn text color="primary"> Primary </v-btn>
<v-btn text color="error"> Error </v-btn>
<v-btn text disabled> Disabled </v-btn>
</v-row>
</v-app>
</template>
...

Tile Buttons

Tile buttons act like regular buttons but have no border radius. You can create them with the tile prop:

<template>
<v-app>
<v-row class="ma-4" justify="space-around">
<v-btn tile> Tile Button </v-btn>
<v-btn tile color="yellow"> Tile Button </v-btn>
<v-btn tile color="blue"> Tile Button</v-btn>
</v-row>
</v-app>
</template>
...

Sizing Buttons

Apart from these variants, Vuetify also provides us with a range of button sizing options to fit a multitude of scenarios:

<template>
<v-app>
<div class="ma-2">
<v-btn x-small color="secondary" dark> Extra small Button </v-btn>
</div>
<div class="ma-2">
<v-btn small color="primary" dark> Small Button </v-btn>
</div>
<div class="ma-2">
<v-btn color="warning" dark> Normal Button </v-btn>
</div>
<div class="ma-2">
<v-btn color="error" dark large> Large Button </v-btn>
</div>
<div class="ma-2">
<v-btn x-large color="success" dark> Extra large Button </v-btn>
</div>
</v-app>
</template>
...

Summary

Buttons are everywhere. The v-btn component from Vuetify allows us to create them and enables various customization options, such as altering the variant or modifying the size.

Sign up for our weekly newsletter to keep up to date with more great content from us!

Get the updated article at codingbeautydev.com.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Written by Tari Ibaba

Thinker + Creator. Sharing news, thoughts, and info on the latest in tech, AI, and computing.

No responses yet

Write a response