Skip to content
TheChatArchiveThe Chat Archive
o1-mini-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

Write an SVG code for a pin icon

  1. User

    Write an SVG code for a pin icon

  2. Assistant

    Sure! Below is an SVG code for a simple and clean pin icon, commonly used in maps and location indicators. You can adjust the width, height, and fill color as needed to fit your design requirements.

    <svg
      xmlns="http://www.w3.org/2000/svg"
      width="24"
      height="24"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
    >
      <path d="M21 10c0 6-9 13-9 13S3 16 3 10a9 9 0 1 1 18 0z" />
      <circle cx="12" cy="10" r="3" />
    </svg>
    

    Explanation:

    • <svg> Element: Defines the SVG container with a width and height of 24 pixels. The viewBox attribute ensures the SVG scales correctly.

    • <path> Element: Draws the outer shape of the pin using a path. The d attribute contains the path data:

      • M21 10: Moves the pen to coordinates (21,10).
      • c0 6-9 13-9 13: Creates a curve that forms the outer shape of the pin.
      • S3 16 3 10: Continues the smooth curve back to the starting point.
      • a9 9 0 1 1 18 0z: Draws a circle with a radius of 9 units to complete the pin shape.
    • <circle> Element: Draws the inner circle of the pin (the "hole" or center point) with a center at (12,10) and a radius of 3 units.

    • Styling Attributes:

      • fill="none": Ensures the pin is not filled, making it an outline.
      • stroke="currentColor": Uses the current text color for the stroke, allowing easy color changes via CSS.
      • stroke-width="2": Sets the width of the stroke lines.
      • stroke-linecap="round" and stroke-linejoin="round": Makes the lines and corners rounded for a smoother appearance.

    Customization:

    • Color: To change the color of the pin, you can modify the stroke attribute. For example, to make the pin red:

      stroke="red"
      
    • Size: Adjust the width and height attributes to resize the icon. For instance, for a 48x48 pixel icon:

      width="48"
      height="48"
      
    • Filled Pin: If you prefer a filled pin icon, you can change fill="none" to a desired color and remove or adjust the stroke attributes. For example:

      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="red">
        <path d="M21 10c0 6-9 13-9 13S3 16 3 10a9 9 0 1 1 18 0z" />
        <circle cx="12" cy="10" r="3" fill="white" />
      </svg>
      

    Feel free to integrate and modify this SVG code to best suit your project's needs!