---
title: "How to remove image source from html content?"  
description: "How to remove image source from html content?"  
author: "Anonymous User"  
published: 2018-03-12  
updated: 2023-05-30  
canonical: https://www.mindstick.com/forum/34428/how-to-remove-image-source-from-html-content  
category: ".net"  
tags: ["asp.net mvc", "mvc4", "razor"]  
reading_time: 2 minutes  

---

# How to remove image source from html content?

Hi,

Here is my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii), I wanna [remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) [source](https://www.mindstick.com/interview/840/what-happens-if-the-both-source-and-destination-are-named-same) from [HTML](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript) content.

Please provide some solution to achieve this task.

```
 <div class="col-md-12">
     @Html.Raw(item.Content)
 </div>
```

## Replies

### Reply by Aryan Kumar

There are a few ways to remove image source from HTML content.

## Using a text editor

You can use a text editor to open the HTML file and remove the image source from each image tag. To do this, find the image tag and delete the src attribute. For example, the following image tag:

Code snippet

```plaintext
<img src="image.jpg" alt="Image">
```

Would be changed to:

Code snippet

```plaintext
<img alt="Image">
```

## Using a web browser

You can also use a web browser to remove image source from HTML content. To do this, open the HTML file in a web browser and right-click on each image. Select "Inspect Element" from the menu. This will open the browser's developer tools. In the developer tools, find the image tag and delete the src attribute. Click "Save" to save the changes to the HTML file.

## Using a programming language

If you are familiar with a programming language, you can use that language to remove image source from HTML content. There are many different programming languages that can be used to do this. For example, you could use Python to write the following code:

Code snippet

```plaintext
import bs4

html_file = open("my_html_file.html", "r")
html_content = html_file.read()

soup = bs4.BeautifulSoup(html_content, "html.parser")

for image in soup.find_all("img"):
    image["src"] = ""

new_html_content = str(soup)

html_file.close()

with open("new_html_file.html", "w") as new_html_file:
    new_html_file.write(new_html_content)
```

This code will open the HTML file, parse it using BeautifulSoup, and then iterate through all of the image tags. For each image tag, the src attribute will be set to an empty string. The new HTML content will then be written to a new file.

Whichever method you choose, make sure to test the changes to the HTML content before you publish it.

### Reply by Hemant Patel

Hi Ethan,

Follow these steps to achieve your task.

Step 1. Write below a line of code at top of the page.

```
@{    string regexImgSrc = @"<img[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>";
}
```

Step 2. And modify your code as follows.

```
<div class="col-md-12">    @Html.Raw(System.Text.RegularExpressions.Regex.Replace(item.Content, regexImgSrc, ""))</div>
```

Hope it's helpful !!!

\


---

Original Source: https://www.mindstick.com/forum/34428/how-to-remove-image-source-from-html-content

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
