What is the best way to add an inset shadow with a transparent background in SVG?

I created a basic SVG Icon, but I'm having trouble adding an inset shadow effect to it. Is there a way to achieve this?

svg {
  filter: drop-shadow(0.1px 1.5px 0.1px rgba(0,0,0,0.5));
}
<!DOCTYPE html>
<html>
<body>

<svg width="124" height="124" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" fill="transparent" stroke="white" stroke-width="1">

<path d="M15.668 8.626l8.332 1.159-6.065 5.874 1.48 8.341-7.416-3.997-7.416 3.997 1.481-8.341-6.064-5.874 8.331-1.159 3.668-7.626 3.669 7.626zm-6.67.925l-6.818.948 4.963 4.807-1.212 6.825 6.068-3.271 6.069 3.271-1.212-6.826 4.964-4.806-6.819-.948-3.002-6.241-3.001 6.241z"/>
    
</svg>
 
</body>
</html>

The desired outcome should look like this: https://i.sstatic.net/kjSPy.png

Answer №1

It appears that your design is focusing on creating a star-shaped outline rather than a solid star shape.

<!DOCTYPE html>
<html>
<body>

<svg width="260" height="245" xmlns="http://www.w3.org/2000/svg" fill="rgb(240, 240, 240)" stroke="transparent" stroke-width="1">
   <filter id="inset-shadow" x="-50%" y="-50%" width="200%" height="200%">
    <feComponentTransfer in=SourceAlpha>
      <feFuncA type="table" tableValues="1 0" />
    </feComponentTransfer>
    <feGaussianBlur stdDeviation="1"/>
    <feOffset dx="0" dy="2" result="offsetblur"/>
    <feFlood flood-color="rgb(20, 0, 0)" result="color"/>
    <feComposite in2="offsetblur" operator="in"/>
    <feComposite in2="SourceAlpha" operator="in" />
    <feMerge>
      <feMergeNode in="SourceGraphic" />
      <feMergeNode />
    </feMerge>
  </filter>
<path filter="url(#inset-shadow)" d="M12 .587l3.668 7.568 8.332 1.151-6.064 5.828 1.48 8.279-7.416-3.967-7.417 3.967 1.481-8.279-6.064-5.828 8.332-1.151z"/>
    
</svg>
 
</body>
</html>

Paulie_D shared some valuable resources which were used and slightly modified to bring you closer to the desired image example.

Edit: The user mentioned a preference for a transparent fill in the comments. Source. This method differs from Sviat Kuzhelev's answer as it involves using one continuous path for the shape instead of creating separate disjointed lines.

<html>

<body>
  <svg>
  <defs>
    <filter id="inset-shadow" width="200%" height="200%">
      <!-- Shadow Offset -->
      <feOffset dx="0" dy="1" />
      <!-- Shadow Blur -->
      <feGaussianBlur stdDeviation="1"  result="offset-blur" />
      <!-- Invert the drop shadow to create an inner shadow -->
      <feComposite operator="out" in="SourceGraphic" result="inverse" />
      <!-- Color & Opacity -->
      <feFlood flood-color="black" flood-opacity=".75" result="color" />
      <!-- Clip color inside shadow -->
      <feComposite operator="in" in="color" in2="inverse" result="shadow" />
      <!-- Shadow Opacity -->
      <feComponentTransfer in="shadow" result="shadow">
        <feFuncA type="linear" slope="1" />
      </feComponentTransfer>
      <!-- Put shadow over original object -->
      <!--<feComposite operator="over" in="shadow" in2="SourceGraphic"/>-->
    </filter>
  </defs>
  <path filter="url(#inset-shadow)" d="M12 .587l3.668 7.568 8.332 1.151-6.064 5.828 1.48 8.279-7.416-3.967-7.417 3.967 1.481-8.279-6.064-5.828 8.332-1.151z" />
</svg>
</body>

</html>

Answer №2

While not a flawless solution, it could be beneficial in your situation. Check out my example below:

<!DOCTYPE html>
<html>
<body>

<svg width="26" height="30" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" fill="transparent" stroke="white" stroke-width="1">
  <defs>
    <filter id="shadow">
      <feDropShadow dx="0" dy="1" stdDeviation=".3"/>
    </filter>
  </defs>

<path style="fill:transparent; filter:url(#shadow);" filter="drop-shadow(.1px 1.5px .1px rgba(0,0,0,0.5))" d="M15.668 8.626l8.332 1.159-6.065 5.874 1.48 8.341-7.416-3.997-7.416 3.997 1.481-8.341-6.064-5.874 8.331-1.159 3.668-7.626 3.669 7.626zm-6.67.925l-6.818.948 4.963 4.807-1.212 6.825 6.068-3.271 6.069 3.271-1.212-6.826 4.964-4.806-6.819-.948-3.002-6.241-3.001 6.241z"/>
    <path 
    stroke="white"
        fill="white"
        stroke-width="1"
    d="
        M 0 11
            L 0 0
            L 12 0
            L 12 3
            L 9 9
            L 0 10
        "
    />
    <path 
    stroke="white"
        fill="white"
        stroke-width="1"
    d="
        M 0 10
            L 0 30
            L 5 30
            L 5 25
            L 6 15
            L 0 10
        "
    />
    <path 
    stroke="white"
        fill="white"
        stroke-width="1"
    d="
        M 3 30
            L 26 30
            L 26 25
            L 21 26
            L 13 20
            L 2 26
        "
    />
    <path 
    stroke="white"
        fill="white"
        stroke-width="1"
    d="
        M 26 0
            L 26 30
            L 20 30
            L 20 26
            L 18 16
            L 23 10
            L 16 10
            L 13 4
            L 13 0
            L 26 0
 
        "
    />
   
</svg>
 
</body>
</html>

P.S. You have the flexibility to experiment with different paths and enhance their visual appeal, in my opinion.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be the reason for the image not showing up on react?

When I try to retrieve the base64 image from the server, it is not displaying properly. Here is the error message I am getting: GET data:image/png;base64,{base64 string} net::ERR_INVALID_URL <img src={data?.gameIcon} alt="" className={st ...

Determining button click events in VueJS using the Watch method

Creating a feature for undo/redo in VueJS involves watching the settings and adding a new element to an array of changes when there is a setting change. Additionally, there is a method for undoing actions when the corresponding button is clicked. An issue ...

Instructions on how to insert a new row into Datatables following the successful submission of a form via AJAX请求

Could someone please provide guidance on how to insert a new row into an existing datatable after a successful AJAX request? Here is the code I am currently using: $(document).ready(()=>{ $.ajax({ url: 'http://localhost:3000/api/post/getUserDat ...

What is the proper method for implementing a scrollable effect to the <v-bottom-sheet> element within the Vuetify framework?

Within my Vue.js project, I am utilizing the v-bottom-sheet component from Vuetify framework (version 2.1.12). Upon reviewing my code, you can observe that the v-card is enclosed within the v-bottom-sheet. The issue arises with the scrollable parameter of ...

Tips for organizing information within a table

I have been developing a tool that allows users to enter a username, and then I display the data fetched from GitHub related to that particular user. Although each cell in the table is sortable, they all seem to sort data based on the first cell. When I cl ...

Retrieve combination values through an AJAX request using ExtJS

My UI is developed using ExtJS, and I have a specific set of tasks that need to be executed when the page loads: Initiate an ajax call to the server to fetch a HashMap. Create a combobox within the main Panel on the page. var combo = Ext.create(' ...

Enhancing the appearance of text in an article by using hover effects, while ensuring the link is attached to the

As I work on the design of my website, I am faced with a challenge involving elements that have links attached to them. I want visitors to be able to click anywhere on the article and be directed to a specific page. The code snippet I currently have is as ...

What are some methods for utilizing the "name" attribute within React components?

About My Coding Environment Utilizing TypeScript and ReactJS The Issue with Using name as an Attribute Encountering the following error: Type '{ name: string; "data-id": string; "data-type": string; }' is not assignable to ...

Grid element not displaying properly as intended

I'm having trouble centering the content of item in the middle column, it just won't budge. .home-grid-container { display: grid; grid-template-columns: auto; grid-template-rows: 0.10fr 0.98fr auto; height: 100vh; } .home-header { g ...

What is the best way to transmit a list item value through a form using a get or post request?

What is the best way to submit a list value using a form? I have a dynamically generated list and I want to send the value of a particular item that is clicked on. I could give each list item a separate name, but since my list is dynamically generated, ...

I am looking to implement a function in JavaScript that will prevent the next button from being enabled until all options

I have a total of 6 dropdown menus along with a next button and previous button. I want the next button to be disabled until all 6 dropdown menus are filled out. Once all 6 dropdown menus are filled, the "next" button should become enabled. Below is the c ...

Transfer information from a single form and distribute it across multiple forms with the help of jQuery or Javascript

Form1 has a variety of input fields including text, select, radio, and textarea. At the bottom there is a button labeled "copy" that allows users to copy data from all the fields in Form1. In different pages, I have three to four other forms with input fi ...

Numerous Controllers in AngularApp failing to function properly

One issue I'm encountering is that only one out of the two controllers within my app seems to be registered: var app = angular.module('MyModule', []); app.controller('FruitCtrl', function($scope) { $scope.fruits = ['appl ...

divs aligned vertically on opposite edges of the webpage

Our web app is being embedded in a third party page as an iframe, but we need to add a bottom "toolbar" with 2 links. One link should be plain text and the other should display our company logo preceded by some text. We want the two links to be positioned ...

There is a property name missing before the colon in the "(property) : (value)" declaration for a CSS global variable

I have been trying to create a global variable in CSS by following the suggestions I found online. According to various sources, including this article, the correct way to declare a CSS variable is as follows: :root{ --variableName:property; } However, ...

Navigating through the Document Object Model within a table

I'm working with an HTML table that contains a delete button in each row's last column. When the button is clicked, I want to delete the entire row. However, my current code only deletes the button itself and not the entire row: var buttons = do ...

Tips for personalizing the webpack compilation process for transforming .vue files into .js files?

As a beginner in the realm of webpack plugins, I've grasped the idea behind the html-webpack-plugin, which empowers users to personalize the generation process of html files by webpack. In a similar vein, I am on the quest for a plugin tailored for . ...

Integrating Vimeo videos into Angular applications

I am attempting to stream videos using URLs in my Angular application. Every time I try, I encounter the following error: Access to XMLHttpRequest at 'https://player.vimeo.com/video/548582212?badge=0&amp;autopause=0&amp;player_id=0&amp;ap ...

Button click does not fill in Jquery Datepicker?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <link type="text/css" href="Styles/Site.css" rel="Stylesheet" ></link > <script type="text/javascript" src= ...

Having several contact forms embedded within a single webpage

I am currently in the process of developing a prototype website and my objective is to have multiple forms on a single page. My goal is to have a form for each service, where users can click on the service and fill out a form to request a quote. The first ...