Creating Basic Shapes with CSS
Tags: css, webdev, frontend, beginners
Published: 2023-03-19 03:48:00


CSS provides a powerful set of tools for creating visually appealing web pages. One of the most commonly used features of CSS is the ability to create basic shapes, such as squares, circles, triangles, parallelograms, and diamonds. In this article, we will explore how to create these shapes using CSS.


![Created By [Author](https://medium.com/@rutikkpatel) ([Rutik Patel](https://medium.com/@rutikkpatel))](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9f62oydompc2s77c4lfj.png)



&nbsp;
## Points to be discussed 

 1. Square

 2. Circle

 3. Triangle

 4. Parallelogram

 5. Diamond

Start with the basic code structure. We have index.html and style.css.

Basic code, which we are going to use for the following functionality:

&nbsp;
### **index.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>Shapes with CSS</title>
      <link rel="stylesheet" href="style.css">
    </head>
    
    <body>
      <div class="main">
    
        <div class="container">
          <div class="ShapeName"> </div>
        </div>
      </div>
    
    </body>
    
    </html>

&nbsp;

### style.css

    * {
      padding: 0;
      margin: 0;
    }
    
    .main {
      height: 100vh;
      width: 100vw;
      display: flex;
      justify-content: center;
      align-items: center;
    }

&nbsp;
As per the above basic code, we need to write the proper class name according to that. So further, we just change from shapeName to any proper shape’s name and style according to it.

**Example : →** <div class="square"></div>


&nbsp;
## 1. Square

**HTML :**

    <div class="square"> </div>

**CSS :**

    .square {
      background: linear-gradient(33deg, #6cacff, #8debff);
      width: 100px;
      height: 100px;
    }

**Preview :**

![](https://cdn-images-1.medium.com/max/2000/1*-PJWVZZE0o2gKsWxhEiJxQ.png)

&nbsp;
##2. Circle

**HTML :**

    <div class="circle"> </div>

**CSS :**

    .circle {
      background: linear-gradient(33deg, #6cacff, #8debff);
      width: 100px;
      height: 100px;
      border-radius: 50%;
    }



**Preview :**

![](https://cdn-images-1.medium.com/max/2000/1*v3DAW7zFU-dgSayfJgWKFA.png)


&nbsp;
## 3. Triangle

**HTML :**

    <div class="triangle"> </div>

**CSS :**

    .triangle {
      width: 0;
      height: 0;
      border-left: 50px solid transparent;
      border-right: 50px solid transparent;
      border-bottom: 100px solid transparent;
      background-color: #6cacff;
    }

*** → Note : **By modifying the border you can also make up-triangle, right-triangle, and left-triangle.*

**Preview :**

![](https://cdn-images-1.medium.com/max/2000/1*rJsnkJihbSlru4qe06Lr_Q.png)

&nbsp;
## 4. Parallelogram

**HTML :**

    <div class="parallelogram"> </div>

**CSS :**

    .parallelogram {
      background: linear-gradient(33deg, #6cacff, #8debff);
      width: 100px;
      height: 50px;
      transform: skew(15deg);
    }



**Preview** :

![](https://cdn-images-1.medium.com/max/2000/1*V7IlYAJxZMI4M6Ym9tOmRA.png)


&nbsp;
## 5. Diamond

**HTML :**

    <div class="diamond"> </div>

**CSS :**

    .diamond {
      background: linear-gradient(33deg, #6cacff, #8debff);
      width: 100px;
      height: 100px;
      transform: rotate(45deg);
    }



**Preview :**

![](https://cdn-images-1.medium.com/max/2000/1*JOAAKindyzoVP2M7InemZA.png)