# How to output text containing html markup without having the browser render the html

**URL:** <https://www.ruby-forum.com/t/how-to-output-text-containing-html-markup-without-having-the-browser-render-the-html/134184>\
**Category:** Rails\
**Created:** [April 8, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/how-to-output-text-containing-html-markup-without-having-the-browser-render-the-html/134184 "2008-04-08T18:03:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/51bf81/32.png) [@eggman2001](https://www.ruby-forum.com/u/eggman2001)\
**Post date:** [April 8, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/how-to-output-text-containing-html-markup-without-having-the-browser-render-the-html/134184/1 "2008-04-08T18:03:49Z")

</div>

I have an object attribute that constantly gets html inserted into it.  
This becomes problematic when I want to output that attribute to the  
browser. What I’d like to do is have the \< and \> converted to \< and  
\>. Is there a snippet or plugin I can use to do this?

---

<div class="post-metadata">

**Author:** ![eggman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/51bf81/32.png) [@eggman2001](https://www.ruby-forum.com/u/eggman2001)\
**Post date:** [April 8, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/how-to-output-text-containing-html-markup-without-having-the-browser-render-the-html/134184/2 "2008-04-08T18:19:42Z")

</div>

> I have an object attribute that constantly gets html inserted into it.  
> This becomes problematic when I want to output that attribute to the  
> browser. What I’d like to do is have the \< and \> converted to \< and  
> \>. Is there a snippet or plugin I can use to do this?

Assuming your attribute is say @html\_string…

\<%= h @html\_string %\>

-philip

---

<div class="post-metadata">

**Author:** ![eggman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/51bf81/32.png) [@eggman2001](https://www.ruby-forum.com/u/eggman2001)\
**Post date:** [April 8, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/how-to-output-text-containing-html-markup-without-having-the-browser-render-the-html/134184/3 "2008-04-08T18:19:42Z")

</div>

You mean like the view helper h(), as in \<%=h my\_attr %\>?

---

<div class="post-metadata">

**Author:** ![eggman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/51bf81/32.png) [@eggman2001](https://www.ruby-forum.com/u/eggman2001)\
**Post date:** [April 8, 2008, 7:21pm UTC](https://www.ruby-forum.com/t/how-to-output-text-containing-html-markup-without-having-the-browser-render-the-html/134184/4 "2008-04-08T19:21:27Z")

</div>

Exactly. Thank you.
