How to render a variable as HTML in EJS?

Sometimes, we want to render a variable as HTML in EJS.

In this article, we’ll look at how to render a variable as HTML in EJS.

How to render a variable as HTML in EJS?

To render a variable as HTML in EJS, we can use various tags.

We write

<% code %>

to run code code which is evaluated but not printed.

We write

<%= code %>

to evaluate and print out code as an escaped string.

And we write

<%- my_form_content %>

to evaluate and print out code as is.

Conclusion

To render a variable as HTML in EJS, we can use various tags.