 <p>My favorite tool for this kind of thing is <a href="http://htmlagilitypack.codeplex.com/" rel="nofollow noreferrer">HtmlAgilityPack</a>. I use it to parse complex HTML documents into LINQ-queryable collections. It is an extremely useful tool for querying and parsing HTML (which is often not valid XML).</p> <p>For your problem, the code would look like:</p> <pre><code>var htmlDoc = HtmlAgilityPack.LoadDocument(stringOfHtml); var images = htmlDoc.DocumentNode.SelectNodes("//img[id=lookforthis]"); if(images != null) { foreach (HtmlNode node in images) { node.Attributes.Append("alt", "added an alt to lookforthis images."); } } htmlDoc.Save('output.html'); </code></pre>