Tailwind CSS - Width



Tailwind CSS Width is a utility class that provides an effective way of handling the content width. This is used to set the width or manipulate the width of any HTML elements.

Tailwind CSS Width Classes

The following is the list of Tailwind CSS Width Classes that provides an effective way of handling content width.

Class CSS Properties
w-0 width: 0px;
w-px width: 1px;
w-0.5 width: 0.125rem; /* 2px */
w-1 width: 0.25rem; /* 4px */
w-1.5 width: 0.375rem; /* 6px */
w-2 width: 0.5rem; /* 8px */
w-2.5 width: 0.625rem; /* 10px */
w-3 width: 0.75rem; /* 12px */
w-3.5 width: 0.875rem; /* 14px */
w-4 width: 1rem; /* 16px */
w-5 width: 1.25rem; /* 20px */
w-6 width: 1.5rem; /* 24px */
w-7 width: 1.75rem; /* 28px */
w-8 width: 2rem; /* 32px */
w-9 width: 2.25rem; /* 36px */
w-10 width: 2.5rem; /* 40px */
w-11 width: 2.75rem; /* 44px */
w-12 width: 3rem; /* 48px */
w-14 width: 3.5rem; /* 56px */
w-16 width: 4rem; /* 64px */
w-20 width: 5rem; /* 80px */
w-24 width: 6rem; /* 96px */
w-28 width: 7rem; /* 112px */
w-32 width: 8rem; /* 128px */
w-36 width: 9rem; /* 144px */
w-40 width: 10rem; /* 160px */
w-44 width: 11rem; /* 176px */
w-48 width: 12rem; /* 192px */
w-52 width: 13rem; /* 208px */
w-56 width: 14rem; /* 224px */
w-60 width: 15rem; /* 240px */
w-64 width: 16rem; /* 256px */
w-72 width: 18rem; /* 288px */
w-80 width: 20rem; /* 320px */
w-96 width: 24rem; /* 384px */
w-auto width: auto;
w-1/2 width: 50%;
w-1/3 width: 33.333333%;
w-2/3 width: 66.666667%;
w-1/4 width: 25%;
w-2/4 width: 50%;
w-3/4 width: 75%;
w-1/5 width: 20%;
w-2/5 width: 40%;
w-3/5 width: 60%;
w-4/5 width: 80%;
w-1/6 width: 16.666667%;
w-2/6 width: 33.333333%;
w-3/6 width: 50%;
w-4/6 width: 66.666667%;
w-5/6 width: 83.333333%;
w-1/12 width: 8.333333%;
w-2/12 width: 16.666667%;
w-3/12 width: 25%;
w-4/12 width: 33.333333%;
w-5/12 width: 41.666667%;
w-6/12 width: 50%;
w-7/12 width: 58.333333%;
w-8/12 width: 66.666667%;
w-9/12 width: 75%;
w-10/12 width: 83.333333%;
w-11/12 width: 91.666667%;
w-full width: 100%;
w-screen width: 100vw;
w-svw width: 100svw;
w-lvw width: 100lvw;
w-dvw width: 100dvw;
w-min width: min-content;
w-max width: max-content;
w-fit width: fit-content;

Functionality of Tailwind CSS Width Classes

  • w-*: This specifies the width and can set a specific length. The * can be replaced with any acceptable value mentioned in the table.
  • min-px: This specifies the width as a 1px value.
  • w-auto: This specifies the width is set according to the content
  • w-1/2: This specifies the width is set to half of the window.
  • w-1/3: This specifies the width is set to one-third of the window.
  • w-1/4: This specifies the width is set to one-fourth of the window.
  • w-1/5: This specifies the width is set to one-fifth of the window.
  • w-1/6: This specifies the width is set to one-sixth of the window.
  • w-1/12: This specifies the width is set to one-twelfth of the window.
  • w-full: This specifies the width is set to full.
  • w-screen: This specifies the width is set to the screen size.
  • w-svh: This class sets the width of the element 100 svw.
  • w-lvh: This class sets the width of the element 100 lvh.
  • w-dvh: This class sets the width of the element 100 ,dvh
  • w-min: This class is used to specify the min-width.
  • w-max: This class is used to specify the max-width.
  • w-fit: This class sets the width to fit the content into the parent.

Tailwind CSS Width Class Examples

The following examples will illustrate the Tailwind CSS Width class utility.

Define Fixed Width

To define a fixed width, we can use classes like 'w-px', 'w-1', and 'w-24' classes. Any valid numeric value(w-*) can be used from the above table to create a fixed width element.

Example

Here in this example, we will create multiple elements and set different fixed widths on each element.





    



    

Tailwind CSS Width Class

w-44
w-40
w-36
w-32
w-28
w-24

Specifying Percentage Width

To specify width in percentage means the width of that element will totally depends on the width of of the parent element. By using 'w-full', 'w-1/2', and 'w-2/5' we can set element width.

Example

Here in this example, we will create multiple elements and set different percentage widths on each element.





    



    

Tailwind CSS Width Class

w-1/12
w-2/12
w-3/12
w-4/12

Define Width Based on Viewport Width

To set the width of an element based on viewport width, we can use the 'w-screen' class. This will auto-adjust the width of your element based on the viewport.

Example

Here in this example we will create two elements, in the first element we will use the 'w-screen' class and leave the second one blank.




    



    

Tailwind CSS Width Class

w-1/12

Full Width Based on Hover

To set the element width full on hover can be achieved by using 'hover' class. But you have to keep one thing in mind that only full width is possible.

Example

Here in this example, we have created an element that takes the full width on hover.




    



    

Tailwind CSS Width Class

Hover over Me
Advertisements