Examples of Creating Shapes Using CSS

1. Creating a square: 

The square is one of the simplest shapes to create with CSS. Here’s an example of how to create a square:

html
<!-- 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>


Output: 

2. Creating Triangle:

Triangles can also be created with CSS. Here’s an example of how to create an upward triangle:

html
<!-- 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>


Output:

By mastering the creation of these shapes with CSS, you can enhance the visual appeal and interactivity of your website.



How to Create Shapes using CSS ?

CSS shapes refer to the geometric shapes that can be created and styled using CSS properties. CSS is a powerful tool that allows web developers to create a variety of shapes using simple CSS properties. From simple squares and circles to complex polygons, CSS provides the tools necessary to design visually appealing elements that can enhance user interaction and overall experience. This article will guide you through the process of creating different shapes using CSS. 

Similar Reads

Try It:

.custom-item { border: 1px solid gray; font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif; border-radius: 3px; margin: auto; margin-top: 5px; max-width: 320px; min-width: 180px; width: 80%; cursor: pointer; background-color: rgb(133, 173, 179); color: rgb(255, 255, 255); font-weight: 600; letter-spacing: 1.5px; padding: 5px; font-size: 13px; } .custom-item:hover { box-shadow: 0 0 2px grey; } .custom-item.active { background-color: rgb(57,149,163); /* Change the background color for the active item */ } .custom-shape { width: 100px; height: 100px; } .rectangle { height: 50px; width: 100px; background-color: #6495ED; } .circle { height: 50px; width: 50px; background-color: #6495ED; border-radius: 50%; } .triangle { width: 0; height: 0; border-left: 25px solid transparent; border-right: 25px solid transparent; border-bottom: 50px solid #6495ED; } .trapezoid { border-bottom: 50px solid #6495ED; border-left: 25px solid transparent; border-right: 25px solid transparent; height: 0; width: 125px; } .parallelogram { width: 100px; height: 50px; transform: skew(20deg); background: #6495ED; } .oval { height: 50px; width: 100px; background-color: #6495ED; border-radius: 50%; } @media screen and (max-width: 500px) { .custom-container { flex-direction: column !important; } .custom-snippets { border-right: none !important; border-bottom: 2px solid; width: 100% !important; padding-bottom: 10px; } }...

Examples of Creating Shapes Using CSS

1. Creating a square:...