Languages
[Edit]
EN

HTML / CSS - simple geometric figures

0 points
Created by:
Eshaal-Wilkinson
774

In this article, we would like to show you how to create simple geometric figures in HTML / CSS.

Simple geometric figures with CSS.
Simple geometric figures with CSS.

Quick solution:

.square {
    background: #b5edc2;
    width: 100px;
    height: 100px;
}

.rectangle {
    width: 150px;
    height: 100px;
    background: #b5edc2;
}

.circle {
    background: #b5edc2;
    border-radius: 50%;
    height: 100px;
    width: 100px;
}

.triangle {
    border-width: 0 60px 100px 60px;
    border-style: solid;
    border-color: transparent transparent #b5edc2 transparent;
    width: 0px;
    height: 0px;
}

Practical examples

Example 1

In this example, we create four basic geometric figures:

  • square
  • rectangle
  • circle
  • triangle 
// ONLINE-RUNNER:browser;

<!DOCTYPE>
<html>
<head>
  <style>
    
    * {
        margin: 10px;
    }

    .square {
        background: #b5edc2;
        width: 100px;
        height: 100px;
    }

    .rectangle {
        width: 150px;
        height: 100px;
        background: #b5edc2;
    }

    .circle {
        background: #b5edc2;
        border-radius: 50%;
        height: 100px;
        width: 100px;
    }

    .triangle {
        border-width: 0 60px 100px 60px;
        border-style: solid;
        border-color: transparent transparent #b5edc2 transparent;
        width: 0px;
        height: 0px;
    }

  </style>
</head>
<body style="display: flex">
  <div class="square"></div>
  <div class="rectangle"></div>
  <div class="circle"></div>
  <div class="triangle"></div>
</body>
</html>

Example 2

// ONLINE-RUNNER:browser;

<!DOCTYPE>
<html>
<head>
  <style>
    
    * {
        margin: 10px;
    }

    .square {
        border: 2px solid #3085d6;
        border-radius: 20px;
        background: #cce1f5;
        width: 100px;
        height: 100px;
    }

    .circle {
        border: 2px solid #3085d6;
        border-radius: 50%;
        background: #cce1f5;
        width: 100px;
        height: 100px;
    }

  </style>
</head>
<body style="display: flex">
  <div class="square"></div>
  <div class="circle"></div>
</body>
</html>

Alternative titles

  1. HTML / CSS - reusable geometric figures for Dirask
  2. HTML / CSS - simple geometric shapes
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join