How to Skew a Button in Tailwind CSS?
Last Updated :
08 Oct, 2024
Skewed buttons can add a dynamic and modern look to your website, Tailwind CSS provides utility classes to easily apply 2D transformations like tilt, rotation, and scaling, we'll explain how to tilt, buttons using Tailwind CSS and create a simple project to demonstrate this.
Approach To Skew A Button
- Decide on the button you want to skew in your UI. This could be a standard HTML button or a custom-styled button.
- Implement the
transform
property with the skew
function. You can specify angles for the skew along the X or Y axes (e.g., skew(-10deg) for X-axis skew). - Check how the skewed button looks on different screen sizes. You might want to use media queries to adjust the skew or other styles based on the viewport.
- Test the button in your design. Make adjustments to the skew angle or styles based on feedback or design requirements.
Steps To Skew A Button
Step 1: Create a New Project
mkdir tailwind-skew-button-gfg
cd tailwind-skew-button-gfg
npm init -y
Step 2: Install Tailwind CSS
npm install tailwindcss postcss autoprefixer
npx tailwindcss init
Step 3: Configure Tailwind CSS
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{html,js}",
],
theme: {
extend: {},
},
plugins: [],
}
Step 4: Add Tailwind Directives to CSS
Create a new src/index.css file and add the following Tailwind directives.
@tailwind base;
@tailwind components;
@tailwind utilities;
Step 5: Build the Tailwind CSS File
npx tailwindcss -i ./src/index.css -o ./dist/output.css --watch
It will create CSS that compiles as dist/output.css.
Project Structure:
Project StructureUpdated Dependencies:
{
"name": "tailwind-skew-button-gfg",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"autoprefixer": "^10.4.20",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.13"
}
}
Example: In this example create a src/index.html
file with a simple button. Here we are using Tailwind's skew-x-12 class to skew the button by 12 degrees on the X-axis, you can adjust the degree of skew by changing the number (e.g., skew-x-6, skew-x-3, etc.)
HTML
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<title>Skew Button with Tailwind CSS</title>
<!-- Link the compiled Tailwind CSS file -->
<link href="../dist/output.css" rel="stylesheet">
</head>
<body class="flex items-center justify-center min-h-screen bg-gray-100">
<div class="text-center">
<!-- GeeksforGeeks Text -->
<h1 class="text-green-600 text-4xl font-bold mb-4">
GeeksforGeeks
</h1>
<!-- Skewed Green Button -->
<button class="bg-green-500 text-white
px-4 py-2 rounded-lg skew-x-12">
Skewed Button
</button>
</div>
</body>
</html>
Output:
Skewed Button
Similar Reads
How To Add Custom Box Shadow In Tailwind CSS? Tailwind CSS is a utility-focused CSS framework. Offers a wide range of design utilities. It does include predefined shading, however, for unique design needs, you might want a custom box shadow that goes beyond the default. in this article, you will learn how to extend Tailwind's default shadow and
3 min read
How to Ceate Swipe-able Button in Tailwind CSS and React? Creating swipe-enabled buttons in React applications can greatly improve user experience, especially on mobile devices, these buttons are typically used for actions like deleting, sharing, and liking items, in this article we'll show you how to create a swipe-enabled button using Tailwind CSS for st
3 min read
How to add a style on a condition in Tailwind CSS ? In this article, we will see how to integrate conditional styling into our web projects using Tailwind CSS. There are various Tailwind CSS classes are available, although, it usually involves dynamically adding or removing classes using JavaScript. There are different approaches to implementing the
3 min read
How to Create Floating Button in Tailwind CSS? A floating button is a popular UI design feature used to quickly access actions like adding, saving, or navigating to website users. We can easily create a floating button in Tailwind CSS. Tailwind CSS makes it very easy to create a floating button with its utility-first approach, which allows us to
4 min read
How to make a CTA Animation with Tailwind CSS ? To enhance the engagement level of your website's Call-to-Action (CTA) elements we use Tailwind CSS utility classes. By directly customizing transition effects with Tailwind CSS, you can effortlessly introduce captivating animation effects to your CTAs, improving user interaction and overall user ex
2 min read