CamKode

Creating a Heart Shape with HTML and CSS

Avatar of Kosal Ang

Kosal Ang

Fri Jan 12 2024

Creating a Heart Shape with HTML and CSS

In this tutorial, we'll explore a simple yet elegant way to craft a heart shape using HTML and CSS. Follow the steps below to bring a charming heart to life on your webpage:

HTML Code:

1<div class="heart"></div>
2

CSS Code:

1.heart {
2  position: relative;
3  width: 200px;
4  height: 200px;
5  background-color: red;
6  transform: rotate(-45deg);
7  margin: 50px;
8}
9
10.heart::before,
11.heart::after {
12  content: '';
13  position: absolute;
14  width: 200px;
15  height: 200px;
16  background-color: red;
17  border-radius: 50%;
18}
19
20.heart::before {
21  top: -100px;
22  left: 0;
23}
24
25.heart::after {
26  top: 0;
27  left: 100px;
28}
29

Now, by combining these HTML and CSS snippets and opening the HTML file in a web browser, you'll witness a visually appealing heart shape. Feel free to experiment with dimensions, colors, and styles to make it uniquely yours!

Related Posts

Create a Responsive Navigation Bar using HTML, CSS, and JavaScript

Create a Responsive Navigation Bar using HTML, CSS, and JavaScript

Creating a beautiful menu bar using HTML, CSS, and JavaScript involves creating the structure with HTML

Creating a Responsive Sidebar with Icons and Expandable Menus

Creating a Responsive Sidebar with Icons and Expandable Menus

If you're looking to build a responsive sidebar with icons and expandable menus, this HTML and CSS template can serve as a great starting point

Beautiful Toggle Switch Using HTML & CSS

Beautiful Toggle Switch Using HTML & CSS

The toggle switch is presented as a sleek rectangular container with rounded corners and a background color. A circular knob, represented...

Building a Responsive Image Slider with HTML, CSS, and JavaScript

Building a Responsive Image Slider with HTML, CSS, and JavaScript

In today's tutorial, we'll guide you through creating a responsive image slider for your website using the power of HTML, CSS, and JavaScript

© 2024 CamKode. All rights reserved

FacebookTwitterYouTube