02 / 04

How do you render < and > in HTML?

Rendering Less Than and Greater Than in HTML

In HTML, the characters < and > are reserved for tags. To display them as normal text on a webpage, you need to use HTML entities so that the browser does not interpret them as HTML syntax.

HTML Entities for < and >
  1. 1

    < → represents the less-than sign (<)

  2. 2

    > → represents the greater-than sign (>)

Example Usage

In short: Use &lt; for < and &gt; for > when you want to render these characters as text in HTML instead of HTML tags.

Difficulty: 3/10
Topics: HTML Entities, XSS Prevention, User-Generated Content

Scenario Questions

0-2 years experience
  1. 1

    We're building a blog where users can post code snippets. If a user writes 'if (x < y && y > z)', the browser tries to parse '< y' as an HTML tag and breaks the page. How would you write this in the raw HTML so it renders exactly as written?

  2. 2

    Imagine you are writing a documentation page for a new framework and you need to display the literal text '<div>Hello World</div>' on the screen without the browser actually rendering a div box. How do you write that in your HTML file?

2-5 years experience
  1. 1

    We have a React component that displays user comments. A user submitted a comment containing 'I <3 coding', but everything after the '<' disappeared on the page. What's happening under the hood, and how would you fix this safely without exposing us to XSS?

  2. 2

    You're consuming an API that returns pre-escaped strings like '<strong>' from a legacy database, but you need to render them as actual bold text in a modern frontend application. What are the security risks of doing this, and how would you safely handle it?

5-8 years experience
  1. 1

    We are building a markdown previewer component. Users can type raw HTML, markdown, and code blocks. How would you design the client-side sanitization pipeline to ensure that code blocks containing '<' and '>' are safely escaped, while legitimate formatting tags like '<b>' are allowed, without introducing XSS vulnerabilities?

  2. 2

    Your team is migrating a legacy jQuery app to a modern SPA framework. The old app heavily relied on '.html()' to insert user-generated strings, which occasionally broke when users typed math symbols like '<' or '>'. How do you systematically audit and refactor these insertion points to use safe DOM APIs, and what fallback strategy would you use for strings that do require rich text?

8+ years experience
  1. 1

    At our scale, we handle millions of user-generated posts daily across multiple micro-frontends. Some teams use React, others use Vue, and some legacy parts use raw templates. How would you design an organization-wide content sanitization and escaping strategy—spanning from the API gateway down to the client-side rendering layer—to prevent XSS while ensuring mathematical symbols and code snippets render correctly?

  2. 2

    We've had a recurring issue where developers bypass framework-level escaping (like using 'dangerouslySetInnerHTML' or 'v-html') to render user content, occasionally leading to security incidents or broken layouts when users type '<' or '>'. How would you implement automated guardrails, linting, or CSP policies to enforce safe rendering practices across a 100+ engineer organization?

Follow-up Questions

  • What is the difference between using '&lt;' and using the unicode escape sequence in JavaScript?
  • How does the browser handle these entities inside a <script> block versus a <textarea>?
  • If you must render raw HTML from an API, how do you prevent XSS while still displaying these characters?