Skip to main content

Creating custom CSS shapes and icons

Creating Custom CSS Shapes and Icons

Custom CSS shapes and icons refer to unique visual elements that are created using Cascading Style Sheets (CSS) rather than using traditional image formats such as JPEG, PNG, or SVG. By using CSS, developers can create custom shapes and icons that can be easily scaled, manipulated, and styled without having to rely on external image files.

Introduction

In this article, we will learn how to create custom shapes and icons using CSS. We will explore different techniques and examples to help you understand how CSS can be used to create unique visual elements for your website.

Creating Shapes with CSS

Creating custom shapes with CSS can be done using a variety of techniques such as using borders, gradients, and pseudo-elements. Let's explore some examples:

Example 1: Triangle Shape

HTML
 
  .triangle {
        width: 0;
        height: 0;
        border-top: 50px solid red;
        border-right: 50px solid transparent;
      }

Example 2: Circle Shape

HTML
 
  .circle {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color: blue;
      }
  
  

Creating Icons with CSS

Icons are commonly used visual elements on websites. Using CSS, we can create custom icons easily. Let's explore some examples:

Example 1: Heart Icon

HTML
 
 .heart {
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 0 25px 25px 0;
        border-color: transparent red transparent transparent;
        transform: rotate(45deg);
      }
    

Example 2: Star Icon

HTML
 
  .star {
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 25px 20px 0 20px;
        border-color: yellow transparent transparent transparent;
        transform: rotate(45deg);
      }
    

Demo

here's some sample code for creating custom icons and shapes using CSS:

Comments

Popular posts from this blog

How to Create a Circular Scroll Progress with HTML, CSS & JavaScript

See the Pen How to Create a Circular Scroll Progress with HTML, CSS & JavaScript by Mushtaq Ahmad ( @MushtaqPhysicist ) on CodePen . How to Create a Circular Scroll Progress with HTML, CSS & JavaScript In this guide, we will explore process of using HTML, CSS, and JavaScript to design a circular scroll progress indicator. This type of indicator displays percentage of a webpage that has been scrolled. Specifically, we will create a circular indicator and position it in bottom right corner of webpage. The indicator's fill level will correspond to amount of page that has been scrolled. HTML Copy Code <!DOCTYPE html> <html lang="en"> <head> <title>Scroll Percentage</title> <!-- Stylesheet --> <link rel="stylesheet" href="style.css"> </head> <body>...

Find Your Location using HTML, CSS & JavaScript

See the Pen Untitled by Mushtaq Ahmad ( @MushtaqPhysicist ) on CodePen . Find Your Location using HTML, CSS & JavaScript It is against policy to access Geolocation in Blogger.com . However, you can still find your location by clicking on CodePen button and then clicking the Get Location button to retrieve your location data Source Code HTML Copy Code <div class="container"> <h1>Find Your Location</h1> <p>Your location: <span id="location"></span></p> <button id="getLocation">Get Location</button> </div> CSS Copy Code body { font-family: Arial, sans-serif; margin: 0; padding: 0; background-color: #f5f5f5; } .container { max-width: 800px; margin: 0 auto; padding: 50px; background-color: #fff; border...

Best practices for using React Router in a React project

Best practices for using React Router in a React project React Router is a popular routing library for React that allows you to create complex, client-side routing for your single-page applications. With React Router, you can create different URLs for different parts of your application, without requiring a full page refresh. Back to TOC Table of Contents • Getting Started • Route Configuration • Nested Routes • Route Params • Programmatic Navigation • Route Guards • Conclusion • Getting Started To get started with React Router, you need to install it as a dependency in your project: Copy Code npm install react-router-dom Once you've installed React Router, you can use it in your React components by importing it: Copy Code import { BrowserRouter as Router, Route, Link } from "react-router-...