Open In App

Tailwind CSS Width

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

This class accepts lots of values in tailwind CSS in which all the properties are covered as in class form. It is the alternative to the CSS Width Property. This class is used to set the width of the text, images. The width can be assigned to the text and images in the form of pixels(px), percentage(%), centimeter(cm) etc. 

Width classes:

  • w-0: This class means the width is set to zero.
  • w-auto: This class means the width is set according to the content
  • w-1/2: This class means the width is set to half of the window.
  • w-1/3: This class means the width is set to one-third of the window.
  • w-1/4: This class means the width is set to one-fourth of the window.
  • w-1/5: This class means the width is set to one-fifth of the window.
  • w-1/6: This class means the width is set to one-sixth of the window.
  • w-1/12: This class means the width is set to one-twelfth of the window.
  • w-full: This class means the width is set to full.
  • w-screen: This class means the width is set to the screen size.
  • w-min:  This class is used to define the min-width.
  • w-max: This class is used to define the max-width.

Note: You can change the number with the valid “rem” values or set the percentage value.

Syntax:

<element class="w-0">...</element>

Example:

HTML




<!DOCTYPE html> 
<head
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" 
          rel="stylesheet"
</head
  
<body class="text-center mx-4 space-y-2"
    <h1 class="text-green-600 text-5xl font-bold">
        GeeksforGeeks
    </h1
    <b>Tailwind CSS Width Class</b
    <div class="flex">
        <div class="w-1/2 bg-green-600 h-12 rounded-l-lg">
          w-1/2
        </div>
        <div class="w-1/2 bg-green-300 h-12 rounded-r-lg">
          w-1/2
        </div>
    </div>
    <div class="flex ...">
      <div class="w-2/5 bg-green-600 h-12 rounded-l-lg">
          w-2/5
      </div>
      <div class="w-3/5 bg-green-300 h-12 rounded-r-lg">
          w-3/5
      </div>
    </div>
    <div class="flex ...">
      <div class="w-1/3 bg-green-600 h-12 rounded-l-lg">
          w-1/3
      </div>
      <div class="w-2/3 bg-green-300 h-12 rounded-r-lg">
          w-2/3
      </div>
    </div>
    <div class="flex ...">
      <div class="w-1/4 bg-green-600 h-12 rounded-l-lg">
          w-1/4
      </div>
      <div class="w-3/4 bg-green-300 h-12 rounded-r-lg">
          w-3/4
      </div>
    </div>
    <div class="flex ...">
      <div class="w-1/5 bg-green-600 h-12 rounded-l-lg">
          w-1/5
      </div>
      <div class="w-4/5 bg-green-300 h-12 rounded-r-lg">
          w-4/5
      </div>
    </div>
    <div class="flex ...">
      <div class="w-1/6 bg-green-600 h-12 rounded-l-lg">
          w-1/6
      </div>
      <div class="w-5/6 bg-green-300 h-12 rounded-r-lg">
          w-5/6
      </div>
    </div>
    <div class="w-full bg-green-300 h-12 rounded-lg">
          w-full
    </div>
</body
  
</html>


Output:



Last Updated : 23 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads