Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create different shapes with CSS?
Shapes can be easily created on a web page with CSS. Not only rectangle, square, or circle, but triangle can also be created. The key to create shapes are the border properties, such border, border-radius, etc.
Create a circle
In this example, we will create a circle using the border-radius property −
border-radius: 50%;
Example
Let us see the example −
<!DOCTYPE html>
<html>
<head>
<style>
.circle {
width: 100px;
height: 100px;
background: rgb(0, 255, 13);
border: 3px solid rgb(27, 0, 78);
border-radius: 50%;
}
</style>
</head>
<body>
<h1>Create a Circle</h1>
<div class="circle"></div>
</body>
</html>
Create a rectangle
In this example, we will create a rectangle using the border property −
border: 3px solid rgb(42, 0, 70);
Example
Let us see the example −
<!DOCTYPE html>
<html>
<head>
<style>
.rectangle {
width: 200px;
height: 100px;
background: rgb(255, 232, 21);
border: 3px solid rgb(42, 0, 70);
}
</style>
</head>
<body>
<h1>Create a Rectangle</h1>
<div class="rectangle"></div>
</body>
</html>
Create a square
In this example, we will create a square using the border property −
border: 3px solid darkblue;
Example
Let us see the example −
<!DOCTYPE html>
<html>
<head>
<style>
.square {
width: 100px;
height: 100px;
background: rgb(23, 153, 121);
border: 3px solid darkblue;
}
</style>
</head>
<body>
<h1>Create a Square</h1>
<div class="square"></div>
</body>
</html>
Create a Triangle
In this example, we will create a triangle using the clip-path property. The polygon() method is used to create a triangle −
clip-path: polygon(50% 0, 100% 100%, 0% 100%);
Example
Let us see the example −
<!DOCTYPE html>
<html>
<head>
<style>
div {
padding: 10%;
border-radius: 2%;
width: 10%;
box-shadow: inset 0 0 80px violet;
clip-path: polygon(50% 0, 100% 100%, 0% 100%);
}
</style>
</head>
<body>
<div></div>
</body>
</html>
Advertisements