Designing Sun, Moon, and Heart Icons with SVG

5 min read

Designing Sun, Moon, and Heart Icons with SVG

In modern web design, icons play a crucial role in communication and user engagement. Creating icons like the sun, moon, and heart with SVG not only enhances performance but also ensures that visuals remain sharp, scalable, and customizable across all devices and screen sizes. In this guide, we’ll explore how to design these three iconic symbols using pure SVG — without relying on external images or icon fonts.

Why Use SVG for Icons?

SVG (Scalable Vector Graphics) is a web standard for describing vector-based graphics in XML format. Unlike raster images (like PNG or JPG), SVGs are resolution-independent — meaning they scale perfectly on high-resolution screens. They also support interactivity, animations, and can be styled dynamically using CSS or JavaScript.

  • Scalable: Icons look crisp on any device, from mobile to 4K displays.
  • Lightweight: SVG files are often smaller than images.
  • Accessible: You can embed SVG directly into your HTML and make it SEO-friendly.
  • Customizable: You can easily change colors, sizes, and effects with CSS.

1. Creating a Simple Sun Icon with SVG

The sun is one of the easiest shapes to create. You can combine a central circle for the sun’s core and lines radiating outward to represent its rays.

<svg width="120" height="120" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg">
  <circle cx="60" cy="60" r="20" fill="gold" />
  <g stroke="orange" stroke-width="4">
    <line x1="60" y1="5" x2="60" y2="25" />
    <line x1="60" y1="95" x2="60" y2="115" />
    <line x1="5" y1="60" x2="25" y2="60" />
    <line x1="95" y1="60" x2="115" y2="60" />
    <line x1="20" y1="20" x2="35" y2="35" />
    <line x1="85" y1="85" x2="100" y2="100" />
    <line x1="20" y1="100" x2="35" y2="85" />
    <line x1="85" y1="35" x2="100" y2="20" />
  </g>
</svg>

This simple design is clean and symbolic. You can modify the stroke and fill colors for different effects — for example, changing the rays to a gradient for a sunrise effect.

2. Designing a Moon Icon with SVG

The moon can be created by overlapping two circles — one representing the visible part and another slightly offset to “cut out” the shadowed area.

<svg width="120" height="120" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg">
  <circle cx="60" cy="60" r="30" fill="lightgray" />
  <circle cx="75" cy="55" r="30" fill="white" />
</svg>

Here, the overlapping white circle acts as the dark side of the moon, creating a crescent shape. You can adjust the cx and cy attributes to modify the curvature of the crescent.

3. Creating a Heart Icon with SVG Path

The heart shape requires using the <path> element — one of SVG’s most powerful tools. The path element uses a series of commands (like M, C, L) to draw curves and lines.

<svg width="120" height="120" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg">
  <path d="M60 100 L20 60 A20 20 0 1 1 60 40 A20 20 0 1 1 100 60 Z" 
        fill="red" stroke="darkred" stroke-width="2"/>
</svg>

This code creates a heart using arcs (A commands) for the curved lobes and lines for the lower tip. It’s a great example of how SVG paths allow you to design organic shapes using mathematical precision.

Real-World Applications

SVG icons are widely used in modern business websites and apps. Companies use custom icons for branding, user interfaces, and storytelling. For example:

  • A weather app uses SVG sun and moon icons to represent different times of day.
  • A health or dating platform uses the heart icon to symbolize care, emotion, or favorites.
  • Businesses customize these SVGs with animation — like a rotating sun or pulsing heart — to make interfaces more engaging.

SEO and Performance Benefits

Using inline SVGs improves performance because they don’t require additional HTTP requests. Search engines can also index SVG markup, allowing icons to contribute to keyword relevance when labeled correctly. Adding title and aria-label attributes helps with accessibility and search optimization.

Conclusion

Designing icons like the sun, moon, and heart using SVG is both creative and practical. It eliminates the need for heavy image files while providing full control over scalability, color, and animation. Whether you’re building a business website, a personal project, or a mobile app interface, SVG empowers you to create visually stunning and efficient icons that stand out on any device.

Building Web Layouts and Interactive Elements with CSS and HTML

Building Web Layouts and Interactive Elements with CSS and HTML

CSS Layouts and Styling Techniques
softwareFrontend Development
View course

Course Lessons