Customizing Breakpoints in Tailwind CSS: A Step-by-Step Guide
Last Updated :
24 Apr, 2025
Tailwind CSS is a utility-first CSS framework that provides a set of pre-defined CSS classes that can be used to quickly style HTML elements. It emphasizes low specificity, and highly composable classes, and encourages consistent design. It is designed to be highly customizable and can be easily integrated with other CSS and JavaScript frameworks. One of the key features of Tailwind is its built-in responsive design support, which allows you to control how your layout and design elements change at different screen sizes.
Breakpoints in Tailwind CSS are specific screen widths at which the layout or design of a website can change. They are used to ensure that the website looks and behaves well on different screen sizes and devices.
For example, a website may have a two-column layout on larger screens but switch to a single-column layout on smaller screens to make the content more readable on mobile devices. These different layouts are achieved by using different CSS styles at different breakpoints.
Breakpoints in Tailwind CSS are defined in the configuration file and can be customized as needed. They are useful because they allow developers to create responsive designs that adapt to the user’s device and screen size, providing a better user experience. Additionally, they allow developers to take advantage of the entire viewport, which can be especially useful when targeting different screen sizes, and ensure that the design is optimized for those screens.
To add tailwind-CSS to your project you can refer to this article: How to setup Tailwind-CSS with Vite?
Default breakpoints in Tailwind-CSS are: The default breakpoints in Tailwind CSS are:
- sm: (576px) – This breakpoint is used for screens with a width of at least 576px, such as small laptops and tablets in portrait mode.
- md: (768px) – This breakpoint is used for screens with a width of at least 768px, such as tablets in landscape mode and larger laptops.
- lg: (992px) – This breakpoint is used for screens with a width of at least 992px, such as large desktop monitors.
- xl: (1200px) – This breakpoint is used for screens with a width of at least 1200px, such as extra-large desktop monitors.
Here is a step-by-step guide to customize breakpoints in Tailwind CSS and override default breakpoints:
Step 1: Installing Tailwind-CSS
First, you will need to install Tailwind CSS in your project. You can do this by referring to this article ‘Setup tailwind-CSS with Vite‘.
Step 2: Open tailwind.config.js file
After installing tailwind css, open the tailwind.config.js file in the root of your project. This file contains the default configuration for Tailwind CSS, including the default breakpoints.
Step 3: Changing the default breakpoints
To change the default breakpoint values, you will need to modify the screens object in the configuration file. For example, to change the default medium breakpoint from 768px to 1024px, you would update the md property in the screens object like this:
Javascript
module.exports = {
screens: {
'sm' : '640px' ,
'md' : '1024px' ,
'lg' : '1280px' ,
'xl' : '1920px' ,
},
}
|
Step 4: Add new custom breakpoints
If you want to add new custom breakpoints, you can simply add new properties to the screens object, for example, if you want to add a breakpoint called ‘2xl’ at 1440px:
Javascript
module.exports = {
screens: {
'md' : '1024px' ,
'lg' : '1280px' ,
'xl' : '1920px' ,
'2xl' : '2140px' ,
},
|
Finally, you will need to update the responsive utilities in your CSS that reference the breakpoints you’ve changed. By doing this, you ensure that your layout will adjust correctly at your custom breakpoints.
Example 1: In this example, we are using ‘md’ breakpoint and the value of the breakpoint ‘md’ is set to ‘1024px’ which means the text background will change from green-600 to green-900.
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< meta name = "viewport" content =
"width=device-width, initial-scale=1.0" >
< title >Welcome to GFG</ title >
< link rel = "stylesheet" href = "style.css" >
</ head >
< body >
< div class="flex justify-center
items-center min-h-screen">
< div class="bg-green-600 p-[53px]
sm:bg-green-900 text-3xl
rounded-[20px] shadow-2xl">
< p >Hello Geeks</ p >
</ div >
</ div >
</ body >
</ html >
|
Output: The output background color will change when the screen width exceeds 1024 pixels as shown in the image:
Example 2: In this example, we are using ‘xl‘ breakpoint, and the value of the breakpoint ‘xl‘ is set to ‘1920px‘ which means the text ‘GeeksforGeeks Learning’ is only visible when the screen size is more than 1920 pixels.
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content =
"width=device-width, initial-scale=1.0" >
< title >Welcome to GFG!</ title >
< link rel = "stylesheet" href = "style.css" >
</ head >
< body >
< div class="flex justify-center
items-center min-h-screen ">
< div class="bg-green-700 hidden
xl:block p-8 text-3xl
rounded-2xl shadow-2xl">
GeeksforGeeks Learning!
</ div >
</ div >
</ body >
</ html >
|
Output:
Explanation: The output will be visible only when the screen width exceeds 1920 pixels.
Conclusion: It is important to keep in mind that when you are customizing the breakpoints, you should also update the utilities that are related to those breakpoints, or your layouts and designs might not work as expected. You can either customize the default breakpoints or you can create new custom breakpoints. By following these steps, you will be able to customize your breakpoints in Tailwind CSS and create a custom responsive design that works perfectly for your project.
Similar Reads
Responsive Breakpoints as Components in Tailwind CSS
Tailwind CSS is a highly-regarded utility-first CSS framework that offers a powerful capability to facilitate the creation of responsive user interfaces: responsive breakpoints as components. This capability allows developers to define custom breakpoints for different screen sizes and apply distinct
4 min read
How to Get Tailwind CSS Active Breakpoint in JavaScript ?
In JavaScript, a Tailwind CSS active breakpoint refers to a specific breakpoint configuration in the Tailwind CSS framework that is currently active, which allows web designers to target specific screen sizes and also consider their styles and functionalities efficiently. In this article, we will se
3 min read
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
Create an Interactive Quiz Form in Tailwind CSS
This article demonstrates creating an engaging quiz using Tailwind CSS and JavaScript. After linking Tailwind CSS to the HTML file, the quiz form is structured and styled using Tailwind's classes. Users interact with the quiz by selecting answers and clicking the result button. JavaScript is then em
9 min read
How to add custom styles and ways to add custom styles in Tailwind-CSS ?
Tailwind is a popular CSS framework that makes your User Interface design making the process easier. It provides low-level classes and those classes combine to create styles for various components. Tailwind-CSS comes with a bunch of predefined styling but as a developer, we need more custom styling
3 min read
Creating Custom Utility Classes in Tailwind CSS and React JS
Tailwind CSS empowers development with a variety of utility classes out of the box, helping us in rapid development and consistent styling. However, In some scenarios, you might want to implement your custom styling. We will discuss the following approaches to create Custom Utility Classes in Tailwi
3 min read
Create Side-by-Side Image Comparison In Tailwind CSS
CSSA side-by-side image comparison feature allows users to compare two images: showcasing "before" and "after" states. This technique is widely used in various fields such as web design, photography, e-commerce, etc. We can also use this technique to highlight differences or improvements between two
2 min read
How to create a Responsive Navigation Bar in Tailwind CSS ?
A Responsive Navigation Bar with collapsible elements is a crucial component of modern web design, allowing users to navigate seamlessly across various screen sizes. In this article, we'll explore how to implement such a navigation bar using Tailwind CSS, a utility-first CSS framework that enables r
2 min read
How to make a Split Navigation Bar in Tailwind CSS ?
Split Navigation Bars in Tailwind CSS implement the different classes that help to distribute the content across the header of a webpage, providing a visually balanced layout. By separating navigation items into distinct sections, it becomes easier for users to identify and access different parts of
3 min read
How to Customize the Font Size in Tailwind CSS ?
Customizing font size in Tailwind CSS involves using the text-[size] utility class, where [size] can be predefined size identifiers like xs, sm, md, lg, xl, or numerical values. Additionally, you can extend the default font sizes in the configuration file for more customization. Syntax<p class="t
2 min read