How to create shapes using CSS ?

In this article, we will design some different types of shapes using CSS. CSS is capable of making all types of shapes.

  • Creating a square:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!-- Write HTML code here -->
    <!DOCTYPE html>
    <html>
      
    <head>
        <style>
            .square {
                height: 50px;
                width: 50px;
                background-color: green;
            }
        </style>
    </head>
      
    <body>
        <div class="square"></div>
    </body>
      
    </html>

    chevron_right

    
    

    Output:

  • Creating Triangle
    • Upward:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      <!-- Write HTML code here -->
      <!DOCTYPE html>
      <html>
        
      <head>
          <style>
              .triangle {
                  width: 0;
                  height: 0;
                  border-left: 25px solid transparent;
                  border-right: 25px solid transparent;
                  border-bottom: 50px solid green;
              }
          </style>
      </head>
        
      <body>
          <div class="triangle"></div>
      </body>
        
      </html>

      chevron_right

      
      

      Output:

    • Downward:
      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      <!-- Write HTML code here -->
      <!DOCTYPE html>
      <html>
        
      <head>
          <style>
              .triangle {
                  width: 0;
                  height: 0;
                  border-left: 25px solid transparent;
                  border-right: 25px solid transparent;
                  border-top: 50px solid green;
              }
          </style>
      </head>
        
      <body>
          <div class="triangle"></div>
      </body>
        
      </html>

      chevron_right

      
      

      Output:

  • Creating a circle:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!-- Write HTML code here -->
    <!DOCTYPE html>
    <html>
      
    <head>
        <style>
            .circle {
                height: 70px;
                width: 70px;
                background-color: green;
                border-radius: 50%;
            }
        </style>
    </head>
      
    <body>
        <div class="circle"></div>
    </body>
      
    </html>

    chevron_right

    
    

    Output:

  • Creating a rectangle:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!-- Write HTML code here -->
    <!DOCTYPE html>
    <html>
      
    <head>
        <style>
            .rectangle {
                height: 50px;
                width: 80px;
                background-color: green;
            }
        </style>
    </head>
      
    <body>
        <div class="rectangle"></div>
    </body>
      
    </html>

    chevron_right

    
    

    Output:

  • Creating a parallelogram:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!-- Write HTML code here -->
    <!DOCTYPE html>
    <html>
      
    <head>
        <style>
            .parallelogram {
                width: 120px;
                height: 60px;
                transform: skew(24deg);
                background: green;
            }
        </style>
    </head>
      
    <body>
        <div class="parallelogram"></div>
    </body>
      
    </html>

    chevron_right

    
    

    Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.